skip to Main Content

I have a solution with multiple projects. I want to obtain (in artifacts) project UserUi.csproj, which is an ASP.NET MVC app (with references to other libraries inside the solution), ready to be copied to a server.

By running this yml:

trigger:
  - master

pool:
  vmImage: "windows-latest"

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

steps:
  - task: NuGetToolInstaller@1

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

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

  - task: VSTest@2
    inputs:
      platform: "$(buildPlatform)"
      configuration: "$(buildConfiguration)"

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

I’m getting weird "deploy" files, and UserUi.deploy.zip file which contains proper files, but in a path:

UserUi.zipContentD_Ca1s4. SampleLayerUserUiobjReleasePackagePackageTmp

Why is that? How can I get just one zip (or normal folder) with PackageTmp contents inside?

I will need to publish this (copy to specified folder) artifacts by using Azure agent installed on server, but with this structure I can’t.

2

Answers


  1. I can reproduce the same situation when using the VSBuild and same arguments.

    How can i just have a one zip (or normal folder) with PackageTmp contents inside?

    To meet your requirement, you can add the following vsbuild argument to directly put the outputs to artifacts folder:

    /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl="$(build.artifactStagingDirectory)\UserUi"
    

    YAML sample:

    pool:
      vmImage: "windows-latest"
    
    variables:
      solution: "**/*.sln"
      buildPlatform: "Any CPU"
      buildConfiguration: "Release"
    
    steps:
      - task: NuGetToolInstaller@1
    
      - task: NuGetCommand@2
        inputs:
          restoreSolution: "$(solution)"
    
      - task: VSBuild@1
        inputs:
          solution: '$(solution)'
          msbuildArgs: '/p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl="$(build.artifactStagingDirectory)\UserUi"'
          platform: '$(buildPlatform)'
          configuration: '$(buildConfiguration)'
    
      - task: VSTest@2
        inputs:
          platform: "$(buildPlatform)"
          configuration: "$(buildConfiguration)"
    
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)UserUi'
          ArtifactName: 'drop'
          publishLocation: 'Container'
    

    In this case, the PackageTmp contents inside will show in a normal folder.

    For example:

    enter image description here

    If you need to package all files, you can use Archive files task to zip the files.

    For more detailed info, you can refer to this doc: Deloy Web App

    Web packages created via the MSBuild task (with default arguments) have a nested folder structure that can be deployed correctly only by Web Deploy.

    Login or Signup to reply.
  2. Try simplifying your VSBuild task. Then use a CopyFiles task to organize only the files you want to deploy from your build. Here is a generic example:

    - task: VSBuild@1
    displayName: 'VS Build'
    inputs:
    solution: '**$(ProjectName).csproj'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    clean: true
    
    - task: CopyFiles@2
    displayName: 'Copy files to staging directory'
    inputs:
    SourceFolder: '$(System.DefaultWorkingDirectory)'
    Contents: |
        $(ProjectName)App_Data**
        $(ProjectName)bin**
        $(ProjectName)appSettings.config
        $(ProjectName)Web.config
        $(ProjectName)Web.$(BuildConfiguration).config
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
    CleanTargetFolder: true
    
    - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'
    inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    

    This one builds only one web project out of my whole solution. But you could build the whole solution too.

    Or, you can also try applying only one of your msbuildargs at a time and viewing the output to see if you can eliminate the one making the crazy file structures.

    You can also add the publishLocation attribute to your PublishArtifacts step to write the PathtoPublish contents directly to another file location without having to retrieve them from your artifacts.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search