问题描述
我对通过 Azure DevOps 实施 CI/CD 还很陌生,我有一个可能是我不确定如何解决的典型场景.我发现处理文件转换的大部分文章都涉及 IIS 部署,但我目前正在使用 .Net Framework 控制台应用程序.
在我的控制台应用程序中,我们有某些设置,通常是文件路径,根据我们所处的环境(Dev、Stage、Prod)以及每个环境中不同的数据库连接字符串而有所不同.
我看到了如何使用变量,例如:__connectionstring__
,可以使用 Tokenizer 应用程序在 Azure DevOps 发布管道中设置和替换这些变量.但是,在我的开发环境中使用该变量不起作用.当我在 Visual Studio 中调试时,它仍然会看到上面的变量名,并且没有像标记器这样的东西来在我的开发机器上本地填充该变量.
有人可以给我指点一篇文章或示例,介绍一种针对我所在的每个环境设置特定应用程序设置的好方法,这将使我仍然可以在本地进行调试,但也可以更改 ADO 发布管道中的设置吗?
您可以使用任务
2、在您的发布管道中添加文件转换任务.
有关 XML 变量替换的更多信息,请查看 此处.
还有第三方替换工具(即Magic Chunks/正则表达式查找和替换 ) 非常方便用于替换 azure 管道中设置文件中的值.请查看此主题中的示例.
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.
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.
这篇关于如何在 Release Pipeline 中更改 Appsettings 和 Config 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!