3

When I run this build, I get a zip file in the drop folder, but opening it up, it has a ton of extra levels. How can I collapse this to just my web folder and its contents that can then be deployed "as-is" to its destination?

opening the zip file I see this
enter image description here

From the root of the zip, the path goes
/Content/D_C/a/1/s/my.app.Web/obj/Debug/Package/PackageTmp
and within PackageTmp I see the content of my published web app. How can I get ONLY this folder to be put into the archived file?

yaml

# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
- dev

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'


# Web
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

[ update 1]
Changed build step to use FileSystem, but the extra folders are still being generated

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
bitshift
  • 6,026
  • 11
  • 44
  • 108

2 Answers2

3

Finally found a solution to this debacle.
Microsoft should update their docs with some of these notes in the VSBuild task section, as this seems pretty common.

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

Now comes trying to understand why this works.
The key missing switches on the msbuildArgs line, as pointed out in the other thread:

/p:UseWPP_CopyWebApplication=true  /p:OutDir="$(build.artifactstagingdirectory)

So now my VSBuild task in the yaml file looks like this:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"  /p:UseWPP_CopyWebApplication=true  /p:OutDir="$(build.artifactstagingdirectory)" 
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

and the publish task like this

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)\_PublishedWebsites'
    ArtifactName: 'drop'
    publishLocation: 'Container'

The end result is I have a sub folder in my drop location that is similar to what I would get when doing a publish from visual studio - but WITHOUT the convoluted folder structure.

bitshift
  • 6,026
  • 11
  • 44
  • 108
  • Thanks for sharing your solution here, would you please accept your solution as the answer? So it would be helpful for other members who get the same issue to find the solution easily. Have a nice day:) – Hugh Lin Sep 08 '20 at 01:46
  • In my case I had to add a backslash at the end of `OutDir` property like so: `/p:OutDir="$(build.artifactstagingdirectory)\\"`. Otherwise the build will fail because apparently the `OutDir` path has a trailing backslash that escaped the end quote. So in the command line it was evaluated as `/p:OutDir="D:\a\1\a`. – pogosama May 25 '22 at 19:30
0

The issue is that you use package as webpublishmethod. This creates a zip package for deployment (to for instance an azure app service) , and adds these extra folders and files. If you change it to filesystem, it will not create a zip, but won't add the extra folders. Since you are publishing the result as an artifact in the next step, there is no reason to zip it, but if you want you can add a manual zip task in between to zip the filesystem output of the build.

These are the settings I usually use to publish to a folder:enter image description here

you can use these settings in a publish profile. This gist describes all ways to include these properties: https://gist.github.com/jonlabelle/5322960fec4043a4720efe827c50fe3b

See also: https://msdn.microsoft.com/en-us/library/e5x4xz73.aspx

https://msdn.microsoft.com/library/dd394698(v=vs.100).aspx!

PaulVrugt
  • 1,682
  • 2
  • 17
  • 40
  • See update above. It seems like the folders are still getting created as before. I end up with a zip file in the drop folder. – bitshift Sep 04 '20 at 17:33
  • Try setting `p:PackageAsSingleFile` to false – PaulVrugt Sep 04 '20 at 18:10
  • 1
    Yes, /p:PackageAsSingleFile=false did the trick. However, I still get the very deep folder structure. How can I get a single sub-folder in the drop location that contains my published web app (see original post above) ? – bitshift Sep 04 '20 at 18:16
  • I've updates the answer with the settings I usually use. You can put these settings in a publish profile – PaulVrugt Sep 04 '20 at 18:17
  • 1
    Interesting - Will the VSBuild task look for a publish profile? I think you have to put it on as a switch, correct ? eg. /p:PublishProfile="profile-name-here" – bitshift Sep 04 '20 at 18:21
  • Yep, updates the answer again with a link with some samples on how to use a profile (or not :) ) – PaulVrugt Sep 04 '20 at 18:23
  • Is that publish profile sample you added above from use within an azure pipeline? I have publish profiles now that I have been using to manually publish to a test server. However, if using a profile within a build task like this, wouldnt you need to set the publishurl = $(build.artifactStagingDirectory) ? – bitshift Sep 04 '20 at 19:27
  • Yes that is a real life profile I use in a pipeline. The staging directory is just a folder, nothing more than that, you can set the publish URL to Any valid location. We publish to a relative subfolder of the project itself. We later publish the artifact from there. But if you want you can also set the publish URL to the staging folder. Whatever floats your boat. – PaulVrugt Sep 04 '20 at 19:35
  • I appreciate your help, but this just isn't working. I've been at this all day long. – bitshift Sep 04 '20 at 20:30
  • I'm not sure what the problem is. I gave you the exact config I use in a different project to publish to a specific folder. What exactly isn't working? Can you update the question with the current task and result with the publish profile? – PaulVrugt Sep 04 '20 at 20:38
  • I managed to find a solution. Still not sure I understand why it works https://stackoverflow.com/questions/55925792/azure-devops-build-task-create-a-zip-with-contents-identical-to-visual-studio-p – bitshift Sep 04 '20 at 20:59