How to include App.config information in an executable help file in .NET?

I have one executable project, say A , which runs another executable project B in a run. To have B.exe in the current working folder A, I add B as a link A, so after compiling a B.exe will be copied to folder A However, I noticed that the configuration that I create for B is not copied or created in folder A (folder A does not have the file B.exe.config, only B.exe ), and therefore things like The trace for B incorrectly configured.

I can, of course, manually copy B.exe.config to folder A , but I'm sure there is some automatic way to do this. Can anyone help me out?

+6
source share
3 answers

You can use events after assembly or ...

In Project A, add the link link to B.exe.config. You do this by adding an existing item to the project. But before clicking the Add button in the file dialog box, click the down arrow to the right of the Add button and select Add As Link. Then install 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 do not mind manually editing the project file, the included file may depend on the configuration of the assembly. The following works for the assembly (although VS2013 will not open the file by double-clicking on the icon in the project tree.)

 <None Include="..\ProjectB\bin\$(Configuration)\B.exe.config"> <Link>B.exe.config</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> 
+5
source

A simpler solution would be to simply include the following in the csproj file. This includes the appropriate file extensions for the referenced files.

  <PropertyGroup> <AllowedReferenceRelatedFileExtensions> .pdb; .xml; .exe.config; .dll.config </AllowedReferenceRelatedFileExtensions> </PropertyGroup> 
+5
source

You cannot have 2 app.configs in the application directory.
Visual Studio will use app.config to launch the project by default.
You can create a message assembly event trigger in which you copy app.config, but this will replace the original app.config file (which I guess contains the data you need).

The best approach (besides creating a clean dll + project architecture) is to manually combine all the configuration data for project A into the configuration data for project B.

-1
source

Source: https://habr.com/ru/post/912401/


All Articles