Azure DevOps 构建任务:创建内容与 Visual Studio Publish 相同的 zip [英] Azure DevOps Build Task: create a zip with contents identical to Visual Studio Publish

查看:13
本文介绍了Azure DevOps 构建任务:创建内容与 Visual Studio Publish 相同的 zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 中,当我们发布到文件夹时,该文件夹包含我们需要部署的内容.

In Visual Studio, when we publish to a folder, that folder contains exactly what we need to deploy.

在 Azure Pipeline 中,构建解决方案任务会生成一堆(对我们而言)不必要的文件和一个 zip 文件(很好!).zip 包含我们需要的文件,但隐藏在一个疯狂的深文件夹路径中:

In Azure Pipeline, the Build Solution task produces a a bunch of (to us) unnecessary files plus a zip file (nice!). The zip contains the files we need, but buried in an crazy deep folder path:

\Content\D_C\a\1\s\src\MyProject\obj\Release\Package\PackageTmp\our-files.dll

我们更喜欢的是:

\our-files.dll

它还修改了 web.config 中的 connectionStrings 以支持它附带的部署脚本.我们不需要那个脚本,而且修改很麻烦(我们通过将<AutoParameterizationWebConfigConnectionStrings>false</...> 添加到 .csproj 文件来禁用它 - 糟糕!)` .

It also modifies connectionStrings in the web.config to support the deploy script it ships with. We don't need that script and that modification is a pain (which we disabled by adding<AutoParameterizationWebConfigConnectionStrings>false</...> to the .csproj file - yuck!)` .

我们尝试在 Build Solution 步骤中对参数大惊小怪:

We tried fussing with the parameters in the Build Solution step:

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"

  • DeployOnBuild 更改为 false 导致 $(build.artifactsstagingdirectory) 为空(导致下一步不部署任何内容)

    • Changing DeployOnBuild to false caused the $(build.artifactsstagingdirectory) to be empty (causing the next step to deploy nothing)

      WebPublishMethod 更改为 FileSystem 没有任何区别(尝试查找有关允许值的文档!)

      Changing WebPublishMethod to FileSystem made no difference (try finding documentation on the allowed values!)

      PackageAsSingleFile 更改为 false 达到了人们的预期 - 没有 zip,但内容仍然隐藏在那个深层文件夹结构中.

      Changing PackageAsSingleFile to false did what one would expect - no zip, but the contents were still buried in that deep folder structure.

      我们的下游脚本可以打开清单文件,xpath 将深度路径烘焙到 zip 中(路径是否总是以 d_C 开头?),解压并抓取那里的内容 - 但多么痛苦,多么不必要.

      Our downstream script could open the manifest file, xpath out the deep path baked into the zip (does the path always start with d_C?), unzip and grab the contents from there - but what a pain and how unnecessary.

      有没有办法只发布一个漂亮干净的构建——一个 zip 的内容可以直接解压到与 Visual Studio 中的纯简发布相同的文件?

      Is there a way to publish just a nice clean build - a zip with contents that directly unpacks to the same files as a plain-jane Publish from Visual Studio does?

      推荐答案

      在 Visual Studio Build 步骤中将MSBuild Arguments"更改为

      In the Visual Studio Build step change "MSBuild Arguments" to

      /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"    /p:UseWPP_CopyWebApplication=true  /p:OutDir="$(build.artifactstagingdirectory)"  
      

      关键是/p:OutDir="$(build.artifactstagingdirectory)" 解决了目录问题,/p:UseWPP_CopyWebApplication=true 删除了 web.config.release 和 web.config.debug

      The key thing is /p:OutDir="$(build.artifactstagingdirectory)" resolves the directory issue and /p:UseWPP_CopyWebApplication=true removes web.config.release and web.config.debug

      然后将发布构建工件步骤发布路径"更新为

      Then update Publish Build Artifacts step "Path to publish" to

      $(build.artifactstagingdirectory)\_PublishedWebsites
      

      这篇关于Azure DevOps 构建任务:创建内容与 Visual Studio Publish 相同的 zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆