I have a class library that is referenced by many other web application projects. It has many settings in its app.config
that I wish to use in all of the referencing web projects. When the class library is built, it copies the app.config
to its own bin
folder as <assembly.name>.dll.config
.
<assembly.name>.dll.config
is copied to the bin folder of each of my referencing web application projects?Copy to Output Directory
or Build Action
(in any combination) does not work.As an aside: It's impractical to manually put all of this config in each of the web application projects. I can read the file by looking for <assembly.name>.dll.config
in the bin folder, and extract the settings from there. I can already do this, so that's not an issue - I just need to ensure the file is going to be there for reading
This can be achieved without 3rd-party tools by adding the following to the class library's project file, assembly.name.csproj
:
// Find this <Import> element for Microsoft.CSharp.targets
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
// Add this <ItemGroup> element immediately after
<ItemGroup>
<Content Include="app.config">
<Link>$(TargetName).dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
This causes the app.config
to be copied to whichever project is referencing it as <assembly.name>.dll.config
. It's good because you only need to configure the one .csproj
file and the effect cascades out to all referencing projects.