VSTS部署IIS应用程序winrm并更改appsettings.json [英] VSTS Deploy IIS App winrm and change appsettings.json

查看:58
本文介绍了VSTS部署IIS应用程序winrm并更改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_ENVIRONMENTappsettings.[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.

例如:

  1. 将相应的appsettings.[environment].json文件(例如appsettings.Production.jsonappsettings.Development.json)添加到项目中,并在每个文件中设置相应的值.
  2. 启动文件中的代码
  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. 为每台环境计算机设置/添加ASPNETCORE_ENVIRONMEN T环境变量(只需设置/添加一次)
  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:

ASP.NET Core中的配置

使用多个环境

如果您仍然想更改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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆