No the guide seems quite clear (to me at least) on how production settings can be put in place. They just talk about how some of this works, but there is no step-by-step guide. I have done the following:
Attempting to change the Environment Variable in Project using this Guide
I get this error despite the Microsoft Doc explicitly stating to reuse ASPNETCORE_ENVIRONMENT
. I cannot save these settings
Ignoring this issue, it looks like you can manually create these entries in launchSettings.json
so I have:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18549/",
"sslPort": 44319
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/v10Staff",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_ENVIRONMENT_T": "Test"
}
},
"IIS Express (Stage)": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/v10Staff",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Stage"
}
},
"ApplicationName": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:60000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_ENVIRONMENT_T": "Test"
}
}
}
Adding Environment Variable to Server
I have added the environment variable according to the documentation I went to Control Panel > System > Advanced system settings.
And added the `New User Variable. "ASPNETCORE_ENVIRONMENT" with value "Stage"
Configuration Piece using this Guide
The next issue I have is, no one shows a working "transform" of the appsettings.Stage.json
. Does it just completely use the Stage file over the appsettings file? Do I need to just explicitly state what is different? That being said here are my files.
appsettings.Stage.json
{
"WebServiceAccount": {
"AccountName": "WebUser",
"AccountPass": "Wedontcarethatthisishere"
},
"ServerLocation": {
"ServerName": "http://appss.domain.com:8080",
"DBConnection": "server=svAppNameSTG;Max Pool Size=6000;database=ES;Integrated Security=SSPI;MultipleActiveResultSets=True"
}
}
appsettings.json
{
"WebServiceAccount": {
"AccountName": "WebUser",
"AccountPass": "testpass1"
},
"ServerLocation": {
"ServerName": "http://appst.domain.com:8080",
"DBConnection": "server=svAppNameTST;Max Pool Size=6000;database=ES;Integrated Security=SSPI;MultipleActiveResultSets=True"
}
}
I know that the settings, and configuration piece are set up correctly. Because our Test environment works. When I deploy this to our Stage server, I have confirmed that it still points to the Test box.
If anyone has a guide or can spot what is wrong with this that would be great.
For Posterity
here is the Startup builder
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();