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?
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With