Search code examples
azure-devopsazure-pipelinesazure-pipelines-build-task

How to publish .NET "Release" artifact?


What do I need to specify for the root file/folder in publish task for MSBuild "Release"?

MSBuild

Is the .NET release basically the binaries? Because for AngularOutput build I had to specify path of the AngularOutput, but for .NET Release, I am not sure what path that would be, I would think it's the entire project, which means... it's the binaries?

binaries

Expected artifact:

expected

Update

Resulting artifact following Kevin's YAML:

root

Inside _PublishedWebsites:

inside

Update 3

When running on Windows agent:

windows

Update 4

Using VSBuild:

steps:
- task: VSBuild@1
  displayName: '.Net build | Build solution'
  inputs:
    solution: 'Project123/*.csproj'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: AnyCPU
    configuration: Release
    msbuildArchitecture: x64

Result is the same, placed in long path:

VS

Update 5

Using /p:PublishProfile=Project123.pubxml MSBuild arg instead, and running on windows agent, the build completes just fine but this time. I get this warning for Publish Task:

##[warning]Directory 'D:\a\1\a' is empty. Nothing will be added to build artifact 'Release'.

I tried adding /p:OutputPath=$(build.artifactstagingdirectory) to the MSBuild args alongside the publish profile arg, and the result is the same one I posted before:

result2

Actually do we even need /p:DeployOnBuild=true? I understand that is to deploy, but I don't think we want or should deploy yet in the pipeline because we have a Release for that specifically to deploy the published artifacts to the App Service.


Solution

  • What do i need to specify for the root file/folder in publish task for MSBuild "Release"?

    When you use the Msbuild task to build your project, the output file will be saved at the Bin folder by default. For example: $(build.sourcesdirectory)/Projectname/bin.

    Based on the structure of your project, the specific path could be different.

    I suggest that you could add msbuild arguments(e.g. /p:OutputPath=$(build.artifactstagingdirectory)) in the Msbuild task.

    For example:

    enter image description here

    In this case, you could set a specific path as the output path. This will make it easier for you to Archive and Publish artifacts.

    Update:

    Ubuntu agent:

    If I don't set the msbuild arg, the output files will show in the bin folder:

    enter image description here

    When I add the msbuild arg, it will upload the files to the target path:

    enter image description here

    They have the same artifacts contents.

    Update2:

    You could try the following sample to create the package for Azure APP service.

    Classic :

    enter image description here

    Yaml:

    steps:
    - task: NuGetToolInstaller@0
      displayName: 'Use NuGet 4.4.1'
      inputs:
        versionSpec: 4.4.1
    
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: Sample.sln
    
    - task: MSBuild@1
      displayName: 'Build solution Sample.sln'
      inputs:
        solution: Sample.sln
        platform: '$(BuildPlatform)'
        configuration: Release
        msbuildArguments: '/p:OutputPath=$(build.artifactstagingdirectory)'
    
    - task: ArchiveFiles@2
      displayName: 'Archive $(Build.ArtifactStagingDirectory)'
      inputs:
        rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact'
      inputs:
        PathtoPublish: '$(build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
      condition: succeededOrFailed()
    

    Result:

    enter image description here

    Update3:

    steps:
    - task: NuGetToolInstaller@0
      displayName: 'Use NuGet 4.4.1'
      inputs:
        versionSpec: 4.4.1
    
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: Sample.sln
    
    - task: MSBuild@1
      displayName: 'Build solution Sample.Web/Sample.Web.csproj'
      inputs:
        solution: Sample.Web/Sample.Web.csproj
        platform: '$(BuildPlatform)'
        configuration: Release
        msbuildArguments: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: drop'
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'