VSTS部署IIS应用程序winrm并更改appsettings.json [英] VSTS Deploy IIS App winrm and change appsettings.json
问题描述
我正在使用部署IIS应用程序Winrm"任务在另一台计算机上部署IIS应用程序.
I am deploying an IIS app on another machine using the "Deploy IIS App winrm" task.
此任务将部署zip文件.在此zip文件中,有一个appsettings.json文件,其变量以下划线开头和结尾.
This task deploys the zip file. In this zip there is an appsettings.json with variables preceding and ending with underscores.
我需要为每个环境替换appsettings.json中的值. 我尝试将json文件放置为"Web部署参数文件"和覆盖参数",但这不起作用.如何更改appsettings.json?
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?
推荐答案
您无需更改appsettings.json.核心项目可以从每个环境变量ASPNETCORE_ENVIRONMENT
的appsettings.[environment].json
文件中检索数据.
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.
例如:
- 将相应的
appsettings.[environment].json
文件(例如appsettings.Production.json
,appsettings.Development.json
)添加到项目中,并在每个文件中设置相应的值. - 启动文件中的代码
- Add corresponding
appsettings.[environment].json
files to project, such asappsettings.Production.json
,appsettings.Development.json
and set the corresponding value in each files. - 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();
}
- 为每台环境计算机设置/添加
ASPNETCORE_ENVIRONMEN
T环境变量(只需设置/添加一次)
- Set/add
ASPNETCORE_ENVIRONMEN
T environment variable to each environment machine (just need to set/add once)
有些文章可以为您提供帮助:
There are some articles that can help you:
如果您仍然想更改appsettings.json文件,则可以解压缩打包的文件,然后使用令牌任务(例如
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
这篇关于VSTS部署IIS应用程序winrm并更改appsettings.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!