Thomas Huijzer

Thomas Huijzer


Share .NET appsettings between multiple projects

Sometimes you want to share the same `appsettings.json` between different .NET projects. After trying different solutions I found that the easiest way is to copy an appsettings file using a Target build option.

For example this directory structure: ``` /Solution /src appsettings.json /Project1 /Project2 ``` When you would like to share the file `/src/appsettings.json` between the two projects you can use this in your project's `.csproj` file: ``` < Target Name="CopyAppSettings" BeforeTargets="BeforeBuild"> < Copy SourceFiles="../appsettings.json" DestinationFolder="./" SkipUnchangedFiles="true" /> < /Target> ``` Now every time you build a project the appsettings file will be copied to the project's directory and the build will continue with the appsettings file in place.