Quantcast
Channel: Merge appsettings.{env}.json into appsettings.json in .NET Core 3.1 - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Brando Zhang for Merge appsettings.{env}.json into appsettings.json in .NET Core 3.1

$
0
0

Asp.net core's appsttings is totally different than the web.config. One is json file another is xml file.

Besides, according to this github issue, you could find Asp.net core program team also don't want to implement this thing.

Here is a workaround, this workaround is not merg, just replace the appsetting.json according to the replace one.

So for all the appsetting.env.json, you need to put all the settings inside it.

You could modify the csporj file by adding below codes:

<ItemGroup><Content Update="appsettings*json" CopyToPublishDirectory="Never" /><FileToRename Include="$(ProjectDir)appsettings.Release.json" /></ItemGroup><Target Name="RenameAppSettingsProd" AfterTargets="Publish"><Message Text="Inside AfterPublish" Importance="high" /><Copy SourceFiles="@(FileToRename)" DestinationFiles="$(PublishDir)appsettings.json" OverwriteReadOnlyFiles="true" /></Target>

Then it just generate one appsettings.json file according to publish environment.

Like below:

I put a specific settings inside the appsetting.release.json.

{"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning"    }  },"AllowedHosts": "*","settings": "release"}

Result:

enter image description here


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>