json.net-coreconfigurationappsettingssln-file

Aggregating .Net Core appsettings.json


I have multiple project under the same solution. My concern is the following:

Is there any way to aggregate all appsettings.json from different projects into one file in the same solution ?


Solution

  • If you are using Visual Studio, use may use "Add as Link" feature (for other code editors, change .csproj manually as described after image):

    Image of "Add as Link" button option

    After you save you project, you will see this new lines in .csproj file (add them manually if you use code editor other than VS, without "Add as link" option):

    <ItemGroup>
      <Content Include="..\appsettings.json" Link="appsettings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
    </ItemGroup>
    

    After that, building that project (from VS or with 'dotnet build') puts "appsettings.json" into your output build folder.