gpt4 book ai didi

azure-pipelines - 如何在 Azure Pipelines 上正确进行文件转换

转载 作者:行者123 更新时间:2023-12-04 14:09:46 27 4
gpt4 key购买 nike

我正在尝试根据我发布到的每个环境对我的 Web.config 进行文件转换。大多数情况下,一切看起来都很好,直到我在发布管道上部署到我的 UAT 阶段。
在我的构建管道中,这是我正在使用的 YAML 文件:

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

pool:
vmImage: 'windows-latest'

variables:
solution: 'SubmissionService.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1
displayName: 'Install Newer Version on NuGet'
inputs:
checkLatest: true

- task: NuGetCommand@2
displayName: 'Restore NuGet Packages for Solution'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: config
nugetConfigPath: ./Nuget.config

- task: VSBuild@1
displayName: 'Create Artifact For Solution'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)" /p:TransformWebConfigEnabled=false /p:AutoParameterizationWebConfigConnectionStrings=false /p:MarkWebConfigAssistFilesAsExclude=false /p:ProfileTransformWebConfigEnabled=false /p:IsTransformWebConfigDisabled=true'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'

这是我的 Web.config的区域我想用文件转换来转换:
 <system.serviceModel>
<client>
<endpoint address="Address_1" name="BasicHttpBinding_1"/>
<endpoint address="Address_2" name="BasicHttpBinding_2" />
</client>
</system.serviceModel>
这是我的 Web.UAT.config :
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<system.serviceModel>
<client>
<endpoint xdt:Transform="Replace" xdt:Locator="Match(name)" address="Address_3" name="BasicHttpBinding_1" />
<endpoint xdt:Transform="Replace" xdt:Locator="Match(name)" address="Address_4" name="BasicHttpBinding_2" />
</client>
</system.serviceModel>
</configuration>


构建流水线工作正常。在我的发布管道中,我在 UAT 阶段有一个“部署 IIS 网站/应用程序”任务,并且我有 XML transformsXML Variable Substitution复选框被选中。
我部署后,UAT web.config 和DEV 阶段的web.config 类似。我创建了另一个任务,文件转换任务,来进行文件转换。该任务显示成功,但配置文件仍未更改。
这是 Azure 日志中表明转换成功的部分:
2020-12-15T16:23:37.1236261Z ==============================================================================
2020-12-15T16:23:37.1236588Z Task : IIS web app deploy
2020-12-15T16:23:37.1236857Z Description : Deploy a website or web application using Web Deploy
2020-12-15T16:23:37.1237081Z Version : 0.178.0
2020-12-15T16:23:37.1237278Z Author : Microsoft Corporation
2020-12-15T16:23:37.1237595Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/iis-web-app-deployment-on-machine-group
2020-12-15T16:23:37.1237965Z ==============================================================================
2020-12-15T16:23:56.5036495Z ConnectionString attributes in Web.config is parameterized by default. Note that the transformation has no effect on connectionString attributes as the value is overridden during deployment by 'Parameters.xml or 'SetParameters.xml' files. You can disable the auto-parameterization by setting /p:AutoParameterizationWebConfigConnectionStrings=False during MSBuild package generation.
2020-12-15T16:23:56.5141446Z [command]C:\agent\_work\_tasks\IISWebAppDeploymentOnMachineGroup_1b467810-6725-4b6d-accd-886174c09bba\0.178.0\ctt\ctt.exe s:C:\agent\_work\_temp\temp_web_package_2874722683939497\Content\D_C\a\1\s\SubmissionService\obj\Release\Package\PackageTmp\Web.config t:C:\agent\_work\_temp\temp_web_package_2874722683939497\Content\D_C\a\1\s\SubmissionService\obj\Release\Package\PackageTmp\Web.UAT.config d:C:\agent\_work\_temp\temp_web_package_2874722683939497\Content\D_C\a\1\s\SubmissionService\obj\Release\Package\PackageTmp\Web.config pw i verbose
2020-12-15T16:23:58.6903744Z XML Transformations applied successfully
我也去了 .csproj文件删除了标签并将配置文件添加为 ,但仍然没有结束。
这是.csproj:
enter image description here
如何正确使用文件转换来转换标签上的地址属性?

最佳答案

How to properly do file transforms on Azure Pipelines


起初我可以在我这边重现这个问题。修改以下注释后,我可以成功转换Azure Pipelines上的文件,您可以检查它是否对您有帮助:
  • 确保您的项目包含转换文件 Web.UAT.config , 和 设置属性 Build Action = "Content" Copy to Output Directory = "Copy Always"
  • 删除了 <DependendUpon>Web.config</DependentUpon>线。这会转储您所有的 web.configs到根。
  • 在构建期间禁用配置转换,添加参数 /p:TransformWebConfigEnabled=False在 Build 任务的 MSBuild Arguments 部分。添加也添加 /p:AutoParameterizationWebConfigConnectionStrings=False如果要在发布期间更新连接字符串。
    注:您可以检查构建管道的工件文件以检查包 .zip包含文件 Web.UAT.config .
  • 设置正确 Transformation rules为任务File transform :-transform **\*.UAT.config -xml **\*.config enter image description here

  • 测试结果:
    enter image description here

    关于azure-pipelines - 如何在 Azure Pipelines 上正确进行文件转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65307637/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com