Visual Studio: copy dependent DLLs to target folde

2019-03-11 07:08发布

I realize that this question has been asked before - but none of the answers apply to my specific case:

  • I have a solution containing a native C++ EXE project, which in turn depends on 40+ native C++ DLL projects (in the same solution).

  • The EXE project has the usual Debug, Release (and Profile) configuration, but since them same source code base is used to build three different applications (say A1, A2 and A3). In addition, it targets x32 and x64, so that's a total of 3 x 3 x 2 = 18 project configurations.

  • The DLL projects are shared by all three target applications, so there are only 3 (Debug, Release, Profile) times 2 (x32, x64) = 6 configurations.

  • Since the EXE project depends on the DLLs, it needs to copy the relevant output of the DLL projects to its target folder (or a subfolder thereof) whenever they are modified.

How would you handle updating of the DLLs?

  • A post-build action in each DLL project doesn't work (well), as it would have to copy the DLL to the relevant output folder of A1, A2 and A3. Any change in an output folder results in having to modify the post-build action in each of the 50 DLL projects.

  • I currently added the DLLs themselves as project items to the EXE project, and configured a custom build tool to copy it to the output folder. But that requires me to add each DLL 6 times, so I end up with 6 x 50 = 300 DLLs!

What I really need is something like a Copy Local option, which unfortunately only works assemblies. Do solution do you suggest to simplify this build setup?

1条回答
劫难
2楼-- · 2019-03-11 07:47

What I'd do is to put all DLLs in a single folder (specific to Debug/Release etc), and copy them back to the appropriate output folder of your EXE.

This can be done in only two actions:

  • Set the output directory of all DLLs to a folder like $(ConfigurationName)_$(PlatformShortName)

    • select all DLL projects
    • right-click -> propoerties
    • select all configurations and all platform
    • set the output dir
  • Add a post-build action to the EXE project, common to all configurations that copies $(ConfigurationName)_$(PlatformShortName)\*.dll to $(TargetDir)

EDIT

There is a problem in the second step since the $(ConfigurationName) of your EXE is not the same as your DLL projects. Not sure but maybe you can have a way to deduce the corresponding configuration, in order to still have a single post-build event for all your 18 configs. It can be a new SO question:)

查看更多
登录 后发表回答