VSTS Deploy IIS App winrm and change appsettings.j

2019-08-25 18:25发布

I am deploying an IIS app on another machine using the "Deploy IIS App winrm" task.

This task deploys the zip file. In this zip there is an appsettings.json with variables preceding and ending with underscores.

I need to replace values in the appsettings.json for each environment. I tried putting the json file as "Web deploy parameter file" and "Overide parameters" but this doesn't work. How can I change the appsettings.json?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-25 19:07

You don’t need to change appsettings.json. The core project can retrieve data from appsettings.[environment].json file per to ASPNETCORE_ENVIRONMENT environment variable.

For example:

  1. Add corresponding appsettings.[environment].json files to project, such as appsettings.Production.json, appsettings.Development.json and set the corresponding value in each files.
  2. Code in Startup file

:

  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();
        }
  1. Set/add ASPNETCORE_ENVIRONMENT environment variable to each environment machine (just need to set/add once)

There are some articles that can help you:

Configuration in ASP.NET Core

Working with multiple environments

If you still want to change appsettings.json file, you can unzip packaged file, then update file by using Token task (e.g. Replace Tokens), then zip these files.

More information, you can refer to Managing Config for .NET Core Web App Deployments with Tokenizer and ReplaceTokens Tasks

查看更多
登录 后发表回答