Unable to configure production server for production

On my production server, I set the environment variable by adding the following to /etc/environment :

  ASPNETCORE_ENVIRONMENT=Production 

I checked that it registered with printenv ASPNETCORE_ENVIRONMENT after reboot.

My server is Ubuntu 14.04 and I am using asp.net core 1.1.

Loads my appsettings.Development.json instead of appsettings.Production.json .

This is my startup.cs constructor

  public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } 

Inside my log file, I can correctly see what it says Hosting environment: Production , but if I output the values ​​from the configuration file for viewing, then these are the values ​​from the contents of appsettings.Development.json .

I even tried removing appsettings.Development.json from the server and rebooting the entire server, but it still pulls out the same values ​​that I think it should be compiled somewhere.

I also tried adding this to .csproj:

  <ItemGroup> <None Include="appsettings.*.json" CopyToPublishDirectory="Always" /> </ItemGroup> 

My settings files are displayed inside VS2017 as follows:

enter image description here

By default, appsettings.json has a defualt value for logging; it does not contain the values ​​that I am pulling.

I can’t understand what the problem is.

+5
source share
2 answers

Perhaps a long shot, but you may have fallen into the same trap as me. During the publishing process, you need to explicitly specify the environment-based appsettings.*.json files. They were not included by default for me, although I did not check the latest project templates to make sure this was true. If you have not verified that the appsettings.Production.json file is appsettings.Production.json present on your appsettings.Production.json server, it might be worth a look.

If it turns out that this is your problem and you are still using project.json , then if your look was similar to mine, you need to add something like this:

  "publishOptions": { "include": [ "wwwroot", "appsettings.json", "appsettings.*.json", "web.config" ] } 

On entering, "appsettings.*.json" is important.

If you upgraded to csproj , then this link can help you figure out what you need in the new project file format.

+3
source

Double-check the value that ASPNETCORE_ENVIRONMENT has when starting the application. For example, if you see Hosting environment: Development in the startup logs, this value is not configured for this process.

Note that export sets the ONLY variable for the current shell, and all processes start from the current shell. For permanent configuration you need to change .bashrc .

0
source

Source: https://habr.com/ru/post/1264772/


All Articles