Web应用程序在Azure DevOps服务器构建过程中未应用Web.config的发布转换

5
我有一个ASP.Net框架(v4.7)的Web应用程序,我在Azure DevOps Server(2019)上有一个构建管道。
有一个Visual Studio Build任务,可以很好地构建解决方案并将站点发布到_PublishedWebsites文件夹。问题是,发布版本的web.config转换没有应用,它仍然设置为debug="true",这不适用于自动部署。
任务的msbuild参数是:/p:outdir="$(build.artifactstagingdirectory)",构建的BuildConfiguration变量设置为release。
当我使用Visual Studio发布项目时,会应用web.release.config转换,并从发布内容的web.config文件中删除debug属性。
我错过了什么吗?
编辑:构建管道YAML:
queue:
  name: Default
  demands: 
  - msbuild
  - visualstudio

#Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references an undefined variable named ‘Parameters.ArtifactName’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'


- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'

    vsVersion: 16.0

    msbuildArgs: '/p:outdir="$(build.artifactstagingdirectory)"'

    platform: '$(BuildPlatform)'

    configuration: '$(BuildConfiguration)'


- task: VisualStudioTestPlatformInstaller@1
  displayName: 'Visual Studio Test Platform Installer'
  inputs:
    versionSelector: latestStable


- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     $(build.artifactstagingdirectory)\*test*.dll
     !**\obj\**

    vsTestVersion: toolsInstaller

    platform: '$(BuildPlatform)'

    configuration: '$(BuildConfiguration)'


- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'

    PublishSymbols: false

  continueOnError: true

- script: |
   cd ProjectName.Web.CMS
   copy cmsimport.lic bin /y
  displayName: 'Copy CMSImport licence to bin folder'

- script: |
   ECHO Copying over the umbraco, umbraco_client and CMSImport content for deployment.

   xcopy ProjectName.Web.CMS\packages\UmbracoCms.7.5.14\UmbracoFiles\umbraco $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\umbraco\ /s /e /r /y
   xcopy "ProjectName.Web.CMS\packages\UmbracoCms.7.5.14\UmbracoFiles\umbraco_client" $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\umbraco_client\ /s /e /r /y
   xcopy ProjectName.Web.CMS\packages\CMSImport.3.5\content\umbraco $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\umbraco\ /s /e /r /y
  displayName: 'Copy umbraco related content to staging'
  enabled: false

- script: |
   cd ProjectName.Web.CMS
   move robots_UAT.txt $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\robots.txt
  displayName: 'Add robots.txt file to artifacts staging directory'

- task: ArchiveFiles@2
  displayName: 'Archive  $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\'
  inputs:
    rootFolderOrFile: ' $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\'

    includeRootFolder: false

    archiveFile: '$(Build.ArtifactStagingDirectory)/ProjectName.Web.CMS.zip'


- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)\ProjectName.Web.CMS.zip'

    ArtifactName: '$(Parameters.ArtifactName)'


发布管道应该进行转换。 - Shayki Abramczyk
@ShaykiAbramczyk 您是正确的,它应该进行转换,但实际上并没有。 - Jason Goodwin
你能分享你的发布流程配置吗? - Shayki Abramczyk
@ShaykiAbramczyk,我已经添加了构建流水线的YAML。 - Jason Goodwin
那么你在构建流程中进行部署吗? - Shayki Abramczyk
@ShaykiAbramczyk 不,这纯粹是用于构建。 - Jason Goodwin
2个回答

4
我在将XDT Transform build task添加到我的Azure DevOps构建服务器后成功应用了转换。
我阅读了一些资料,发现作为CI/CD管道的一部分,转换是通过Azure App Service发布或IIS发布发布任务应用的,而不是由msbuild执行。 这篇文章也很有趣。不幸的是,文件转换构建任务是预发布版本,如果您使用Azure DevOps Server on-prem,则必须自己构建任务源代码。我尝试了一下,但在安装包后,该任务没有显示为可添加。XDT转换任务是一个很好的替代品,并且可以很好地完成工作。

0

只有在项目(csproj)文件中编写了以下任务,msbuild才会执行转换

<Target Name="AfterBuild"> </Target>
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="Web_config_AfterBuild" AfterTargets="AfterBuild" Condition="Exists('Web.$(Configuration).config')">
   <TransformXml Source="Web.config" Destination="$(OutputPath)Web.config" Transform="Web.$(Configuration).config" /> 
</Target>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接