我试图根据我发布到的每个环境,在Web.config文件上执行文件转换。大部分情况下,一切看起来都很好,直到我在发布管道上部署到我的UAT阶段。
在我的构建管道中,这是我使用的YAML文件:
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.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变换
和XML变量替换
复选框。
部署完成后,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://learn.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 文件:
如何正确使用文件转换来转换标签上的地址属性?