Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: copy dependent DLLs to target folder

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?

like image 409
Daniel Gehriger Avatar asked Feb 10 '11 10:02

Daniel Gehriger


People also ask

How do I change the target directory in Visual Studio 2019?

To place all solution outputs in a common directory Click on one project in the solution. On the Project menu, click Properties. In each project, depending on its type, select either Compile or Build, and set the Output path or Base output path to a folder to use for all projects in the solution.

Where are DLL files located in Visual Studio project?

C:\Program Files\MyApp\Modules\SomeModule. dll.


1 Answers

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:)

like image 65
CharlesB Avatar answered Sep 28 '22 10:09

CharlesB