I have one executable project, let's say A
, which is launching another executable project B
in the run. In order to have a B.exe
in A's current working folder, I add B as A's reference so that after the compilation a B.exe
will be copied into A
's folder. However, I noticed the configuration that I make for B
is not copied or generated in A's folder (there is no B.exe.config file in A
's folder, only B.exe
), and hence the stuff such as tracing for B
is not configured correctly.
I can of course copy the B.exe.config
manually to A
's folder, but I bet there is some automatic way to do that. Could anybody help me?
You can use post-build events, or...
In Project A, add a link reference to B.exe.config. You do this by adding an existing item to the project. But, before pressing the Add button on the file dialog, press the down arrow on the right of the Add button and select "Add as Link." Then, set the file to copy to the output directory. In your project file, it will look something like this:
From ProjectA.csproj:
<None Include="..\ProjectB\bin\Debug\B.exe.config">
<Link>B.exe.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
If you don't mind manually editing your project file, the included file can depend on the build configuration. The following works for builds (though VS2013 will not open the file when you double-click on the icon in the project tree.)
<None Include="..\ProjectB\bin\$(Configuration)\B.exe.config">
<Link>B.exe.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
A much simpler solution would be to simply include the following in the csproj file. This includes the matching file extensions for the referenced files.
<PropertyGroup>
<AllowedReferenceRelatedFileExtensions>
.pdb;
.xml;
.exe.config;
.dll.config
</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
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