I'm trying to deploy an asp.net core 2.0 api project on IIS from a mac.
What I'd like to do is set up different appsettings.json files for my development, staging and production environments, and then call the different environment with dotnet -build as part of my deployment scripts.
I've looked at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments which is for an older version of .net core and I can't get my head around what I need to do. Rather than setting the environment for the OS, I'd like to set it programatically (as my staging and production environments are for the same server)
I have an appsettings.Development.json file which is used when I run my app, but I can't seem to get my appsettings.Production.json file loaded when simply setting the environment variable as part of the build command.
bash$ ASPNETCORE_ENVIRONMENT=Production dotnet run
Using launch settings from /Properties/launchSettings.json...
Hosting environment: Development
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
Ultimately I'm trying to deploy a specific connection string depending on the environment that I build for. Is there a better way to do this?
Update
@Chris's answer below helped, in addition I found the following:
Per IIS Application Pool If you need to set environment variables for individual apps running in isolated Application Pools (supported on IIS 10.0+), see the AppCmd.exe command section of the Environment Variables topic in the IIS reference documentation.
Which let me set up different environments per app pool
appsettings.{environment}.json
files in code – Setappsettings.production.json
for production, anappsettings.staging.json
for staging andappsettings.development.json
for development. One thing to remember is that if no other appsettings files are found, thenappsettings.json
is used. – Jamie Taylorappsettings.json
is always used. The environment-specific files simply override. – Chris Pratt