0

I'd like to clean up the generated build of my app so that the app's folder contains a specific folder hierarchy where all of the various automatically included .dll's are placed in a second level folder and not right alongside my .exe

How would i go about doing this in a C# VS2019 solution?

Desired Example structure:

[App]
  [Resources]
    Newtonsoft.Json.dll
    System.Data.SQLite.dll
    etc...
  [Data]
    Data.sqlite3
    etc...
  Launcher.exe
  App.config
Reahreic
  • 596
  • 2
  • 7
  • 26

1 Answers1

0

After a day of digging and trial and error, the following solution can be used to generate a clean, custom, styled, hierarchy for the build folder.

1) Add 'probing privatePath=MyFolder' to your project's App.config file.

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

2) Add a target node with 'AfterBuild' to your project file. (Open your apps .csproj file in a text editor) Then add one <move> node for each assembly .dll that's just dumped next to your .exe with the source set to the assembly dll you want to move and the destination set to $(OutDir)\MyFolder

<Target Name="References" AfterTargets="AfterBuild">
  <Move SourceFiles="$(OutDir)\MyAssemblyClutter.dll" DestinationFolder="$(OutDir)\MyFolder" />
</Target>

Note: Build > Clean won't remove your custom folders or their content after this.

For bonus points (credit to Jason Morse), to ensure that NuGet packages don't dump their debugging .pdf and documentation .xml files into your release build folder, add the following to your project file within the '<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">' node.

<AllowedReferenceRelatedFileExtensions>
  <!-- Prevent default XML and PDB files copied to output in RELEASE. Only *.allowedextension files will be included-->
  .allowedextension
</AllowedReferenceRelatedFileExtensions>
Reahreic
  • 596
  • 2
  • 7
  • 26