如何在 Release Pipeline 中更改 Appsettings 和 Config 信息
How to change Appsettings and Config info in Release Pipeline
我对通过 Azure DevOps 实施 CI/CD 还很陌生,我遇到了一个我不确定如何解决的典型场景。我发现处理文件转换的大多数文章都涉及 IIS 部署,但我目前正在使用 .Net Framework 控制台应用程序。
在我的控制台应用程序中,我们有一些特定的设置,通常是文件路径,它们根据我们所处的环境(Dev、Stage、Prod)而不同,并且数据库连接字符串在每个环境中都不同。
向我展示了如何使用变量 ex: __connectionstring__
,可以使用 Tokenizer 应用在 Azure DevOps 发布管道中设置和替换这些变量。但是,在我的开发环境中使用该变量是行不通的。当我在 Visual Studio 中进行调试时,它仍然会看到上面的变量名称,并且没有类似分词器的东西来在我的开发机器上本地填充该变量。
谁能给我指点一篇文章或示例,让我知道如何让应用程序设置特定于我所处的每个环境,这将使我仍然可以在本地进行调试,但也可以更改 ADO 发布管道中的设置?
要转换非网络应用程序的.config 文件,我总是使用SlowCheetah:
- https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms
- https://github.com/microsoft/slow-cheetah
它的工作原理与 web.config
转换一样,但对于 app.config
。
您可以使用任务 File transform 替换 Azure DevOps 发布管道中的某些设置。
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.
例如,您有以下 appsetting.json 文件。并且您想将默认日志级别更改为错误。
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
1、首先需要在发布管道编辑页面的Variables
部分定义一个发布变量Logging.LogLevel.Default
,并赋值Error
。见下文
2、在发布管道中添加文件转换任务。
有关XML变量替换的更多信息,请查看here。
还有第三方替换工具(即。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。
我对通过 Azure DevOps 实施 CI/CD 还很陌生,我遇到了一个我不确定如何解决的典型场景。我发现处理文件转换的大多数文章都涉及 IIS 部署,但我目前正在使用 .Net Framework 控制台应用程序。
在我的控制台应用程序中,我们有一些特定的设置,通常是文件路径,它们根据我们所处的环境(Dev、Stage、Prod)而不同,并且数据库连接字符串在每个环境中都不同。
向我展示了如何使用变量 ex: __connectionstring__
,可以使用 Tokenizer 应用在 Azure DevOps 发布管道中设置和替换这些变量。但是,在我的开发环境中使用该变量是行不通的。当我在 Visual Studio 中进行调试时,它仍然会看到上面的变量名称,并且没有类似分词器的东西来在我的开发机器上本地填充该变量。
谁能给我指点一篇文章或示例,让我知道如何让应用程序设置特定于我所处的每个环境,这将使我仍然可以在本地进行调试,但也可以更改 ADO 发布管道中的设置?
要转换非网络应用程序的.config 文件,我总是使用SlowCheetah:
- https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms
- https://github.com/microsoft/slow-cheetah
它的工作原理与 web.config
转换一样,但对于 app.config
。
您可以使用任务 File transform 替换 Azure DevOps 发布管道中的某些设置。
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.
例如,您有以下 appsetting.json 文件。并且您想将默认日志级别更改为错误。
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
1、首先需要在发布管道编辑页面的Variables
部分定义一个发布变量Logging.LogLevel.Default
,并赋值Error
。见下文
2、在发布管道中添加文件转换任务。
有关XML变量替换的更多信息,请查看here。
还有第三方替换工具(即。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。