【问题标题】:Web.config release transform not being applied as part of web application build in Azure DevOps serverWeb.config 发布转换未作为 Azure DevOps 服务器中 Web 应用程序构建的一部分应用
【发布时间】:2019-07-23 08:12:33
【问题描述】:

我有一个 ASP.Net 框架 (v4.7) Web 应用程序,我在 Azure Devops Server (2019) 中有一个构建管道。

有一个 Visual Studio 构建任务可以很好地构建解决方案并将站点发布到 _PublishedWebsites 文件夹。问题是,该版本的 web.config 转换尚未应用,它仍然有 debug="true" 设置,这不是我想要的自动部署。

任务的 msbuild 参数是:/p:outdir="$(build.artifactstagingdirectory)",并且构建的 BuildConfiguration 变量设置为 release

当我使用 Visual Studio 发布项目时,应用了 web.release.config 转换,并且已从发布内容中的 web.config 文件中删除了调试属性。

这里有什么我遗漏的吗?

编辑:构建管道 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)'

【问题讨论】:

  • 发布管道应该进行转换
  • @ShaykiAbramczyk 你是对的,它应该转换,但它没有。
  • 你能分享你的发布管道配置吗?
  • @ShaykiAbramczyk 我已经为构建管道添加了 YAML。
  • 那么你在构建管道中进行部署吗?

标签: asp.net msbuild azure-devops continuous-integration


【解决方案1】:

在将 XDT Transform build task 添加到我的 Azure DevOps 构建服务器后,我设法应用了转换。

我做了一些阅读,表明转换作为 CI/CD 管道的一部分被应用为 Azure 应用服务部署或 IIS 部署发布任务的一部分,而不是由 msbuild 执行。

This 也是一篇有趣的文章。不幸的是,文件转换构建任务是预发布的,如果您在本地使用 Azure DevOps Server,则必须自己从源代码构建任务。我试了一下,但是在安装软件包后,任务没有显示为可添加。 XDT 转换任务是一个很好的替代品,并且做得很好。

【讨论】:

    【解决方案2】:

    只有在您的项目 (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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多