Stage / Production Asp.net Core Script Deployment

No manual seems perfectly clear (at least to me) about how production settings can be set. They just talk about how it works, but there is no step-by-step guide. I have done the following:

Attempting to change an environment variable in a project using Guide

I get this error even though the Microsoft Doc explicitly claims to reuse ASPNETCORE_ENVIRONMENT . I can not save these settings

Shows a next to ASPNETCORE_ENVIRONMENT

Ignoring this problem, it looks like you can manually create these entries in launchSettings.json , so I:

 { "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 an environment variable to the server

I added an environment variable according to the documentation that I sent to Control Panel > System > Advanced system settings. , and added a new user variable. "ASPNETCORE_ENVIRONMENT" with the value "Stage"

Configuration Using This Guide

The next question I have is that no one shows the "conversion" of appsettings.Stage.json . Does it just make full use of the Stage file over the appsettings file? Is it just necessary to directly indicate what is different? Here we are talking about 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 part of the configuration are configured correctly. Because our test environment is working. When I deploy this to our Stage server, I confirmed that it still points to the Test field.

If someone has a guide or you can determine what is wrong with this, that would be great.

For poster

here is the startup constructor

 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(); 
+5
source share
1 answer

First of all, you are trying to use the ASPNETCORE_ENVIRONMENT variable several times in your first screenshot. You should not add new variables, but rather change the value of the variable to reflect the environment you want to use. To test Stage locally, just change the value ASPNETCORE_ENVIRONMENT variable from Development to Stage .

I have not come across using the ASPNETCORE_ENVIRONMENT_T variable for anything. If this is what you added, I suspect that this is due to a misunderstanding of the above, and probably the best way to achieve what you want. It should be emphasized that everything that is in launchSettings.json relates to your local machine / development environment.


Setting the ASPNETCORE_ENVIRONMENT variable at your stage or on production servers will vary depending on how you host it. IIS? Azure? AWS? Docker? The following answer discusses setting environment variables for IIS:

Publish to IIS by setting the environment variable


As for appsettings.json , the values ​​are combined. First, everything is first read from the base file, and then everything read from appsettings.{env.EnvironmentName}.json will add or overwrite what is in the base file. In the given example, the variable WebServiceAccount / AccountName can be omitted from appsettings.Stage.json , since it is identical to the value in the database.

+4
source

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


All Articles