I had an application in production using .net core RC1 running on IIS. I re-wrote the application because the company wanted it on .net core1 since that is the official release.
In my .net core RC1 application I had config.json and config.production.json and in the production version I simply included the settings I wanted overridden like the connection string. That worked fine.
In .net core1 I have appsettings.json and appsettings.production.json. However, the connection string doesn't seem to be getting updated. It seems to use the localdb from the original appsettings.json.
appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-DecisionEff-b32ae861-2422-4f88-839c-2a6d599fee45;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
appsettings.production.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=mydb.server;Database=DbName;User ID=User;Password=password;Trusted_Connection=False; Connection Timeout= 30;"
}
}
In my startup file I do have it set to look for production:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
The above was modeled after what I was doing in RC1 that worked. Was there something else that changed so connections strings are not udpated? If I put the production db connection string in the appsettings.json file then the application works fine on our production server. So it is not pulling the setting from the appsettings.production.json file. I know it is reading the environment properly because I am printing it out and it is as expected.
How do you provide different development and production db settings in .net core 1 web app?
Any help would be appreciated. I am obviously overlooking something.
UPDATE: When I run this on my local machine setting ASPNETCORE_ENVIRONMENT to Production it uses the proper connection string. So the web app is seeing the proper environment on production and can use the connection string. Is there something that has to be configured during build to send the different environment settings? Or is there a way it can print the different settings from the .json files for the environments?
UPDATE 2: I noticed that when I publish the application the there is only appsettings.json which has the localdb connection only. There doesn't seem to be any appsettings.production.json file generated. Is there somewhere you have to specify during the build now that these different settings should come across?