Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps Build Task: create a zip with contents identical to Visual Studio Publish

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

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

What we would prefer is:

\our-files.dll

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!)` .

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)\\"
  • Changing DeployOnBuild to false caused the $(build.artifactsstagingdirectory) to be empty (causing the next step to deploy nothing)

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

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

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.

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?

like image 208
biscuit314 Avatar asked Apr 30 '19 17:04

biscuit314


People also ask

What is difference between build and release in Azure DevOps?

A Build Pipeline is used to generate Artifacts out of Source Code. A Release Pipeline consumes the Artifacts and conducts follow-up actions within a multi-staging system. It is best practice to establish a link between a Build Pipeline and the corresponding Release Pipeline.

Is it possible to copy build artifact from pipeline into repo?

Unfortunately, it is not possible to pass build artifacts from one Pipeline to another as it is only intended to work for steps. As a workaround, you can use the Downloads section of your repository to upload and get build artifacts.

How do I upload an entire folder to Azure DevOps?

In Visual Studio, connect to your Azure DevOps project. Choose View > Other Windows > Source Control Explorer. In Source Control Explorer, navigate to the folder where you want to add the files or folder.

How do I add a task group to a release pipeline?

Select a sequence of tasks in a build or release pipeline, open the shortcut menu, and then choose Create task group. Specify a name and description for the new task group, and the category (tab in the Add tasks panel) you want to add it to.


1 Answers

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)"  

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
like image 177
Jon Morley-Jones Avatar answered Oct 18 '22 02:10

Jon Morley-Jones