12

First

There are several questions similar to this, but none have answers that solved my problem nor can I post in them. The closest one is in this question.

I found the answer here. And I am posting here so I can found it later.

The Question: How to build my project and have all my Referenced Library inside a lib sub-folder?

A want this output directory:

Lots of DLLs in the main folder

To be stay like this:

enter image description here

1 Answer 1

32

I found the answer here and transcribed here for the case of the link die.

In your App.config file, insert this:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
</configuration>

Then go to Project -> Properties --- right click in your Project, then in the ContextMenu select Properties.

Now go to Build Events and add the following code inside the Post-build event command line text box (as you can see in the bellow image).

; Move all assemblies and related files to lib folder
ROBOCOPY "$(TargetDir) " "$(TargetDir)lib\ " /XF *.exe *.config *.manifest /XD lib logs data /E /IS /MOVE
if %errorlevel% leq 4 exit 0 else exit %errorlevel%

Post-build event command line

After

Build your project and say good bye to your OCD!

3
  • Good to know that ! :)
    – Prany
    Commented Jul 6, 2018 at 13:56
  • 2
    Note that this breaks debugging on other projects that reference this project for some reason. When executing those other projects, this project is unable to find it's dependent DLLs for some reason. Commented Jul 29, 2019 at 20:27
  • Looks like App.config file doesn't work for Net console application or am I missing something?
    – Arugin
    Commented Sep 21, 2023 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.