如何在 Azure-DevOPS 发布管道中使用 XML 转换进行 IIS 部署?
How to do IIS Deployment with XML Transformation in Azure-DevOPS Release pipeline?
如何使用 XML 转换为 IIS 部署创建发布管道
我在 azure 中创建了一个构建管道 devops.I 我正计划创建一个发布管道,它需要将 3 个 IIS 网站(DEV、QA、STAG)中的构建部署到预置服务器(我没有使用 Azure服务器)
根据我的研究,我在应用程序中创建了 3 个配置,每个配置中都有它们的环境特定值
当我使用 IIS 部署任务时,我可以选择 select xml transformation.How xml 转换是否有效?
Xml改造只有在配置文件(web.config)和改造文件(web .stage
.config) 位于指定包内的同一文件夹中。有关详细信息,您可以查看此 official site
转换文件 是一个 XML 文件,指定 Web.config 文件在部署时应如何更改。对于它的语法,你可以检查这个(https://docs.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110))
所以在你的情况下,首先你应该指定一个配置文件(例如Web.config)和三个转换文件 ,转换文件应根据其环境配置命名(例如 web.dev.config、web.qa.config、web.stag.config)。
在这三个转换文件中,指定需要用XDT语法转换的元素和属性(检查上面的语法link)(XML-Document-Transform)。
其次:您应该在发布管道中分别创建三个阶段,分别命名为dev、qa、stag。
第三:为每个阶段启用 XML transformation
IIS Web App Deploy 任务。
希望以上内容对您有所帮助?
参考以下步骤:
第 1 步:创建一个 Asp.net Web 应用程序(名称:SalesDemo)
步骤 2.1:创建嵌套配置(例如 web.SalesDemoQA.config、web.SalesDemoStag.config、web.SalesDemoProd.config),复制到输出目录:始终)
9 月 2 日 2 在文本编辑器中打开您的 csproj 文件并检查以下内容
<None Include="web.SalesDemoQA.config">
<DependentUpon>web.config</DependentUpon>
</None>
将上面的代码改成下面的代码
<Content Include="web.SalesDemoQA.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content >
步骤 2.3 web.SalesDemoQA.config
中的示例代码
<connectionStrings>
<add name="SalesDemo" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=SalesDemoDBQA;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
第 3 步:登录到 Azure DevOPS 站点
第 4 步:创建构建管道
步骤 4.1:Select 一个 Repsotiory
步骤 4.2:Select 模板(Asp.net 模板)
9 月 4.3 msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False /p:PackageLocation="$(build.artifactstagingdirectory)\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
注意:我在msBuildArgs中添加了以下附加参数
/p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False
步骤 4.4:发布构建工件
步骤 5 创建发布管道
步骤 5.1:创建阶段名称:(SalesDemoQA)
步骤 5.2:创建 IIS Web 应用程序管理任务
步骤 5.3:创建 IIS Web 应用部署任务
步骤 5.4:设置(包或文件夹:$(System.DefaultWorkingDirectory)/_SalesDemo/drop/SalesDemo.zip;
步骤 5.5:检查 XML 转换选项
假设 web.SalesDemoQA.config 文件将被转换为 web.config 文件。
注意:阶段名称与配置名称匹配(www.salesDemo.config)
如何使用 XML 转换为 IIS 部署创建发布管道
我在 azure 中创建了一个构建管道 devops.I 我正计划创建一个发布管道,它需要将 3 个 IIS 网站(DEV、QA、STAG)中的构建部署到预置服务器(我没有使用 Azure服务器)
根据我的研究,我在应用程序中创建了 3 个配置,每个配置中都有它们的环境特定值 当我使用 IIS 部署任务时,我可以选择 select xml transformation.How xml 转换是否有效?
Xml改造只有在配置文件(web.config)和改造文件(web .stage
.config) 位于指定包内的同一文件夹中。有关详细信息,您可以查看此 official site
转换文件 是一个 XML 文件,指定 Web.config 文件在部署时应如何更改。对于它的语法,你可以检查这个(https://docs.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110))
所以在你的情况下,首先你应该指定一个配置文件(例如Web.config)和三个转换文件 ,转换文件应根据其环境配置命名(例如 web.dev.config、web.qa.config、web.stag.config)。
在这三个转换文件中,指定需要用XDT语法转换的元素和属性(检查上面的语法link)(XML-Document-Transform)。
其次:您应该在发布管道中分别创建三个阶段,分别命名为dev、qa、stag。
第三:为每个阶段启用 XML transformation
IIS Web App Deploy 任务。
希望以上内容对您有所帮助?
参考以下步骤:
第 1 步:创建一个 Asp.net Web 应用程序(名称:SalesDemo)
步骤 2.1:创建嵌套配置(例如 web.SalesDemoQA.config、web.SalesDemoStag.config、web.SalesDemoProd.config),复制到输出目录:始终)
9 月 2 日 2 在文本编辑器中打开您的 csproj 文件并检查以下内容
<None Include="web.SalesDemoQA.config">
<DependentUpon>web.config</DependentUpon>
</None>
将上面的代码改成下面的代码
<Content Include="web.SalesDemoQA.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content >
步骤 2.3 web.SalesDemoQA.config
中的示例代码 <connectionStrings>
<add name="SalesDemo" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=SalesDemoDBQA;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
第 3 步:登录到 Azure DevOPS 站点
第 4 步:创建构建管道
步骤 4.1:Select 一个 Repsotiory
步骤 4.2:Select 模板(Asp.net 模板)
9 月 4.3 msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False /p:PackageLocation="$(build.artifactstagingdirectory)\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
注意:我在msBuildArgs中添加了以下附加参数 /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False
步骤 4.4:发布构建工件
步骤 5 创建发布管道
步骤 5.1:创建阶段名称:(SalesDemoQA)
步骤 5.2:创建 IIS Web 应用程序管理任务
步骤 5.3:创建 IIS Web 应用部署任务
步骤 5.4:设置(包或文件夹:$(System.DefaultWorkingDirectory)/_SalesDemo/drop/SalesDemo.zip;
步骤 5.5:检查 XML 转换选项
假设 web.SalesDemoQA.config 文件将被转换为 web.config 文件。
注意:阶段名称与配置名称匹配(www.salesDemo.config)