1

I have a Window Forms C# project with some external references and references to other class library projects in the same solution too.

When I build the Window Form project, I want only the referenced libraries be stored in a different location (eg: bin\Release\Libraries), and not in the same folder as the .exe.

Is it possible to do?

This question was here already 2 years ago, but with no sufficient answer :How to save DLLs in a different folder when compiling in Visual Studio?

I need to place just several third party assemblies into separate folder during the build. If I will change build-path it will place all the assemblies there, and that is not what I want.

Community
  • 1
  • 1
marek_lani
  • 3,895
  • 4
  • 29
  • 50
  • Wandering on the SO I found your question. I [answered here](https://stackoverflow.com/a/51211161/5734097), it was the only solution that worked perfectly for me. – D.Kastier Sep 24 '19 at 16:29

2 Answers2

1

You can add a post-build event to your project that moves the third party DLLs from the output folder bin\Release to the subfolder.

Right click on the project, select properties and then Build Events

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • I tried this copy /Y "$(TargetDir)cairo).dll" "$(SolutionDir)lib\cairo.dll" but I am getting exited with code 1 error, and cairo.dll is surely present – marek_lani Mar 27 '13 at 11:41
  • That looks wrong. Try removing the parentheses after `cairo`: `copy /Y "$(TargetDir)cairo.dll" "$(SolutionDir)lib\cairo.dll`. Furthermore, make sure the folder `lib` actually exists in `$(SolutionDir)`. Actually, based on your question, I think it should be `$(TargetDir)` instead. – Daniel Hilgarth Mar 27 '13 at 11:47
  • And please besides this I have probably stupid question, but how do I update references and PATH. Because When I add reference to specific dll it is automaticaly copied into build-path, I want to take it and move to the folder where the other necessary dlls are copied on post build event – marek_lani Mar 27 '13 at 12:51
  • 1
    I have found solution, all I need to do is postbuild move created assemblies and than add to congif file that program should look into specific subdirectory. http://stackoverflow.com/questions/2445556/c-sharp-putting-the-required-dlls-somewhere-other-than-the-root-of-the-output – marek_lani Mar 27 '13 at 13:17
1

Add a post build event onto the project in visual studio that copies the DLLs you want to the relevant location.

You will then need to update your references and probably set a PATH variable to make sure the project knows where they are located

g7876413
  • 279
  • 2
  • 9