Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App.config for child project not being copied to output

Tags:

I have a solution with two executable projects.

Main.exe is dependent on Subordinate.exe.

These projects both have App.config files, so in their respective output directories, I have Main.exe.config and Subordinate.exe.config.

When I build Main.exe, Subordinate.exe is copied into Main's output directory, but Subordinate.exe.config is not.

Is there a standard way to tell Visual Studio to do this?

like image 225
Mud Avatar asked Jan 17 '12 18:01

Mud


2 Answers

Another way I found is by adding the app.config file as a linked file to the dependent project, e.g. here you would add a link to Subordinate.exe's app.config into Main.exe's project, and set it to be copied to the output directory when built. You can then change the name of the file that is copied to Main.exe's output directory at build time by editing the <Link> element in your project file, something like:

<None Include="..\Subordinate.ProjectFolder\app.config">
  <Link>Subordinate.exe.config</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

This has the same issue that you have to hardcode the name of the generated config file, but that's no worse than the AfterBuild approach, and I find this method a little more transparent, and it removes the build-order dependency issue that you mentioned.

like image 81
adrian Avatar answered Oct 05 '22 23:10

adrian


Right click on the Main project and select Edit Project File. Add an AfterBuild event:

  <Target Name="AfterBuild">
    <Copy SourceFiles="..\Subordinate\bin\$(Configuration)\Subordinate.exe.config" 
          DestinationFolder="$(TargetDir)" />
  </Target>
like image 40
KMoraz Avatar answered Oct 06 '22 00:10

KMoraz