Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to load the correct appsettings.json? #5481


User avatar
0
squaresunion created

Hello Guys, I noticed that in the native code of server side code (angular 5 .Net core) to read the appsettings.json file using this code JObject.Parse(File.ReadAllText("appsettings.json")); Is this working if I create a file appsettings.Production.json will this read the correct production file automatically if I change the ASPNETCORE_ENVIRONMENT to production? Or it is going to find appsettings.json on the drive? How does this work?

Regards


7 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Reading of appsetting.json with environment variable is done at <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Configuration/AppConfigurations.cs#L34">https://github.com/aspnetzero/aspnet-ze ... ons.cs#L34</a>

  • User Avatar
    0
    squaresunion created

    <cite>ryancyq: </cite> Reading of appsetting.json with environment variable is done at <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Configuration/AppConfigurations.cs#L34">https://github.com/aspnetzero/aspnet-ze ... ons.cs#L34</a>

    ok thanks but does that mean that if you have a custom appsettings.environment.json, with the above code it will loaded natively the correct file? Do I need to change the code for it to work properly?

  • User Avatar
    0
    squaresunion created

    I create a appsettings.staging.json file change the environment variable ASPNETCORE_ENVIRONMENT to staging but when I do an update-database it is still pointing to the dev environment. The default appsettings file...How should I do

  • User Avatar
    0
    ryancyq created
    Support Team

    <cite>SquaresUnion: </cite> I create a appsettings.staging.json file change the environment variable ASPNETCORE_ENVIRONMENT to staging but when I do an update-database it is still pointing to the dev environment. The default appsettings file...How should I do

    Yes. Given a custom appsettings.environment.json, if you set the environment variable correctly, it will be loaded automatically.

  • User Avatar
    0
    squaresunion created

    <cite>SquaresUnion: </cite> I create a appsettings.staging.json file change the environment variable ASPNETCORE_ENVIRONMENT to staging but when I do an update-database it is still pointing to the dev environment. The default appsettings file...How should I do

    OK I am reading the doc. What I am trying to do will never work. I got the right way to proceed thanks

  • User Avatar
    0
    maliming created
    Support Team

    The Update-Datebase command will not use the environment.

    See: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.EntityFrameworkCore/EntityFrameworkCore/AbpZeroTemplateDbContextFactory.cs#L15">https://github.com/aspnetzero/aspnet-ze ... ory.cs#L15</a>

    <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Configuration/AppConfigurations.cs#L17">https://github.com/aspnetzero/aspnet-ze ... ons.cs#L17</a>

  • User Avatar
    0
    squaresunion created

    <cite>maliming: </cite> The Update-Datebase command will not use the environment.

    See: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.EntityFrameworkCore/EntityFrameworkCore/AbpZeroTemplateDbContextFactory.cs#L15">https://github.com/aspnetzero/aspnet-ze ... ory.cs#L15</a>

    <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Configuration/AppConfigurations.cs#L17">https://github.com/aspnetzero/aspnet-ze ... ons.cs#L17</a>

    Yes I saw that. It working for me now. Great thanks for you quick answer.

    Regards