when refering to a library assembly, it is auto copied to the final bin directory. However the *.dll.config is not, is there a way to automatically copy this config file?
Using configuration files in DLL is not trivial, but is very simple. Using configuration files in DLL is not trivial.
Now you might be wondering what happens behind the scenes. Well, when you compile your application, the compiler actually copies the app. config file to the output folder, but gives it another name: When you start your application (ConsoleApp1.exe in our example), the matching config file will be loaded too.
The reason dll. config exists at all is because VS doesn't distinguish between libraries and EXEs when it needs to generate config settings. Therefore if you happen to be inside a library and VS needs to generate a config entry it'll generate it in a dll.
There is a better answer in the following post:
Visual Studio/MSBuild copy referenced class library's app.config as *.dll.config to bin folder of current project
// Add this <ItemGroup> at the end of your .csproj file before </Project> and after <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Content Include="app.config">
<Link>$(TargetName).dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
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