如何在发布管道中更改Appsettings和Config信息 [英] How to change Appsettings and Config info in Release Pipeline

查看:32
本文介绍了如何在发布管道中更改Appsettings和Config信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于通过Azure DevOps实施CI/CD来说,我还是一个新手,我不确定如何解决典型的方案.我发现有关文件转换的大多数文章都涉及IIS Deploy,但我目前正在使用.Net Framework控制台应用程序.

在我的控制台应用程序中,我们具有某些设置(通常是文件路径),这些设置会根据我们所处的环境(Dev,Stage,Prod)以及在每个环境中不同的数据库连接字符串而有所不同.

向我展示了如何使用变量 ex:__connectionstring __ ,该变量可以使用Tokenizer应用在Azure DevOps发布管道中进行设置和替换.但是,在我的开发环境中使用该变量是行不通的.当我在Visual Studio中进行调试时,它仍然会看到上面的变量名,并且没有像令牌生成器之类的东西来在我的开发计算机上本地填充该变量.

有人可以为我提供一篇文章或示例,以一种很好的方式为我所处的每种环境提供特定的应用程序设置,使我仍然可以在本地调试,还可以更改ADO发布管道中的设置吗?

解决方案

您可以使用任务

2,在发布管道中添加文件转换任务.

有关XML变量替换的更多信息,请查看魔术块/ RegEx查找&替换),这非常方便,可用于替换azure管道中的设置文件中的值.请在此线程中查看示例./p>

I’m fairly new to implementing CI/CD through Azure DevOps and I have what is probably a typical scenario that I’m not sure how to address. Most of the articles I’ve found dealing with file transformation deal with IIS Deploy but I’m currently working with .Net Framework console apps.

In my console apps we have certain settings, usually file paths, that are different based on the environment we are in (Dev, Stage, Prod) as well as the database connection string being different in each environment.

I was shown how to use variables, ex: __connectionstring__, that can be set and replaced in a Azure DevOps release pipeline using the Tokenizer app. However, having that variable in my development environment doesn’t work. When I debug in Visual Studio it still sees the above variable name and doesn’t have something like the tokenizer to populate that variable locally on my development machine.

Can someone point me to an article or example on a good way to have appsettings specific to each environment I’m in that will allow me to still debug locally but also change the settings in the ADO release pipeline?

解决方案

You can use task File transform to replace certain settings in Azure DevOps release pipeline.

Variables defined in the build or release pipeline will be matched against the 'key' or 'name' entries in the appSettings, applicationSettings, and connectionStrings sections of any config file and parameters.xml. Variable Substitution is run after config transforms.

For example you have below appsetting.json file. And you want to change the default log level to Error.

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

1, First you need to define a Release Variable Logging.LogLevel.Default in the Variables section of the release pipeline edit page with the value Error assigned to it. See below

2, Add the File transform task in your release pipeline.

For more information about XML variable substitution, please check it out here.

There are also third party substitution tools(ie. Magic Chunks/ RegEx Find & Replace ) that are very convenient to use to replace the values in your settings files in azure pipeline. Please check out the example in this thread.

这篇关于如何在发布管道中更改Appsettings和Config信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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