Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting .NET Core appsettings.json appsettings.development.json and appsettings.release.json

I have two asp.net core console apps.

First one has appsettings json files as shown below.

appsettings json files nested

As you can see they are nicely nested.

The second core project is also console project. I have added appsettings json files but they are nested.

What am I missing

appsettings json files not nested

like image 822
VivekDev Avatar asked Dec 17 '25 18:12

VivekDev


2 Answers

I had the same issue in my console application.

I noticed the following string in my project file

<Project Sdk="Microsoft.NET.Sdk">

I changed it to

<Project Sdk="Microsoft.NET.Sdk.Worker">

After I saved the project, the settings files became nested.

like image 170
MirrorBoy Avatar answered Dec 19 '25 14:12

MirrorBoy


You can edit the project file to add this element:

<ItemGroup>
        <None Update="appsettings.Development.json">
            <DependentUpon>appsettings.json</DependentUpon>
        </None>
    </ItemGroup>
    <ItemGroup>
        <None Update="appsettings.Release.json">
            <DependentUpon>appsettings.json</DependentUpon>
        </None>
    </ItemGroup>

result:

enter image description here

Don't forget to reload your project if you edit it outside of Visual Studio.

like image 43
Yiyi You Avatar answered Dec 19 '25 13:12

Yiyi You