Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we autocopy the *.dll.config? [duplicate]

Tags:

c#

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?

like image 213
user705414 Avatar asked May 07 '11 02:05

user705414


People also ask

Can DLL have config file?

Using configuration files in DLL is not trivial, but is very simple. Using configuration files in DLL is not trivial.

Does app config get compiled?

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.

Why DLL config is created?

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.


1 Answers

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>
like image 128
SwissCoder Avatar answered Oct 26 '22 04:10

SwissCoder