Search code examples
c#visual-studionuget

Visual Studio 2022 place referenced dll into subdirectory of bin folder


I have created a c#-project in Visual Studio 2022 which is using the nuget-package "Microsoft.Data.SqlClient". This package brings along about 60(!) dll, so that my \bin\release folder is now really full.

To get more clarity in this folder, I was wondering if these dll could be placed in a subdirectory of \bin\release, for example \bin\release\dll.

I'm also wondering why there are *.xml and *.pdb files genereated for every *.dll file in \bin\release. Could this be suppressed?

Thanks for any suggestions! Tobias


Solution

  • As you said, you are using .net framework, you can refer to the following steps to achieve your requirement:

    First, you can add post build event in property of the project to move the DLLs into lib folder: enter image description here

    You can refer to this command line in post build event:

    ROBOCOPY "$(TargetDir) " "$(TargetDir)lib\ " /XF *.exe *.config *.manifest  /XD lib logs data /E /IS /MOVE if %errorlevel% leq 4 exit 0 else exit %errorlevel%
    

    Then add this code in your App.config file:

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

    It looks like this: enter image description here

    Finally build the project it will be clean in the folder and the .exe file works fine. enter image description here