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 this is the official version.
In my RC1 application for the .net kernel, I had config.json and config.production.json, and in the production version I just turned on the settings that I wanted to override as the connection string. This worked fine.
In .net core1 I have appsettings.json and appsettings.production.json. However, the connection string does not seem to be updated. It seems to be using 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 boot file, I have a search function:
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 did in RC1, which worked. Was there anything else that changed so that the connection strings were not obstructed? If I put the production db connection string in the appsettings.json file, then the application works fine on our production server. Therefore, it does not pull the setting from the appsettings.production.json file. I know that he reads the medium correctly, because I print it, and it is as expected.
How do you provide various settings for development and production in a .net core 1 web application?
Any help would be greatly appreciated. I obviously missed something.
UPDATE: When I run this on my local machine ASPNETCORE_ENVIRONMENT in Production, it uses the correct connection string. Thus, the web application sees a suitable production environment and can use the connection string. Should it be configured at build time to send various environment parameters? Or is there a way to print various settings from .json files for the environment?
UPDATE 2: I noticed that when I publish the application, there is only appsettings.json which has only localdb connection. There seems to be no appsettings.production.json file. Is there somewhere that you should specify during build now that these different settings should meet?