4

I've made my first proof of concept ASP.NET Core application, I have 5 appsettings files:

  1. appsettings.json
  2. appsettings.Development.json
  3. appsettings.Test.json
  4. appsettings.Staging.json
  5. appsettings.Production.json

I'm running the app in IIS so I actually have web.config files so that I can set the ASPNETCORE_ENVIRONMENT environment variable on a per application basis:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.webServer>

    <aspNetCore processPath="dotnet" >
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development"></environmentVariable>
      </environmentVariables>
    </aspNetCore>

  </system.webServer>

</configuration>

I have 4 web.config transforms so I can publish from Visual studio, and it will set the correct environment variable value for each environment.

When I publish to each environment though it publishes all the appsettings files. Is it possible to get it to publish on the root appsettings.json and the applicable environment specific one, but omit the others?

1 Answer 1

3

No, it's not possible. ASP.NET Core is not like ASP.NET. In ASP.NET, you literally published for the environment; if you wanted to switch to a different environment, you'd need to republish. ASP.NET Core is published for all environments. The same published app can be picked up and moved to any environment, without change. The actual environment is generally externalized, such as via and environment variable, and can be changed on a whim, without requiring new code to be deployed. This is actually a feature of ASP.NET Core.

Now, the way you're handling the environment variable does somewhat make it dependent on the publish, but that's just modifying the web.config, which itself only has meaning when deploying to IIS. ASP.NET Core itself doesn't care about or use web.config, and honestly doesn't even care about or use release configurations.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, thanks. The only reason I used the web.config was to configure on a per application basis, as apposed to setting the environment for all applications on the server.
That's fine. It just doesn't actually change anything as far as your app is concerned. It could still potentially be run against any environment, so all the environment-specific JSON files are equally valid to be part of the publish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.