1
votes

I have created an application using dotnet core. I am building it as a self-contained package. I am attempting to publish it to an Azure artifact server using the pipeline UI. I have been able to successfully build the self-contained package, and have been able to successfully publish it to the drop. I have not been able to figure out how to get the NuGet pack command (and subsequent Nuget push) to pick up the self-contained package to place as a downloadable package on the artifact server.

Here is the YAML for my publish task:

steps:

- task: DotNetCoreCLI@2

  displayName: 'dotnet publish'

  inputs:

    command: publish

    publishWebProjects: false

    projects: '**/TelemetryReceiver.csproj'

    arguments: '-c release -r win-x64 --self-contained true'

Here is the YAML for the task that copies to build staging:

Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

steps:

- task: CopyFiles@2

  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'

  inputs:

    SourceFolder: '$(build.sourcesdirectory)'

    Contents: '**\bin\$(BuildConfiguration)\**'

    TargetFolder: '$(build.artifactstagingdirectory)'

Here is the YAML for publish:

steps:

- task: PublishBuildArtifacts@1

  displayName: 'Publish Artifact: drop'

  inputs:

    PathtoPublish: '$(build.artifactstagingdirectory)\src\TelemetryReceiver\bin\Release\netcoreapp2.2\win-x64'

And here is the YAML for the NuGet pack:

steps:

- task: NuGetCommand@2

  displayName: 'NuGet pack'

  inputs:

    command: pack

    packagesToPack: src/telemetryreceiver/telemetryreceiver.csproj

    versioningScheme: byPrereleaseNumber

On the copy step, the logs indicate the full self-contained package is indeed being copied to "\src\TelemetryReceiver\bin\Release\netcoreapp2.2\win-x64". But one the final package is downloaded from the artifact server, it is only picking up the contents of the "netcoreapp2.2" directory.

I am confused, of course, about how the "dotnet publish" and "NuGet pack" tasks are supposed to relate. It seems as if both independently evaluate the .csproj file and that is it.

1
You are using a couple of different technologies where you can do everything with dotnet commands: First use dotnet pack to create the .nupkg file, then use dotnet push command to push the nupkg to the nuget feed.Rob Bos
I switched out to just the .NET Core commands, added a "dotnet pack" and "dotnet push", then disabled the prior "NuGet Pack" and "NuGet Push" tasks. The outcome was the same. I am uncertain of the relationship between the "dotnet publish" and the "dotnet pack" commands. The publish seems necessary to create the self-contained package, but the pack command uses the .csproj file to create the package. I don't see how I take the output of the publish command and give it to the pack command.WayneRoseberry
Are you doing the pack as the first take and then the push?Rob Bos
Yes. It goes "publish, pack, push"WayneRoseberry
Do you have a nupkg file in your artifacts now? Is there a warning from the push step?Rob Bos

1 Answers

0
votes

How to publish self-contained dotnet core package via pipeline UI to azure artifacts?

You may misunderstand the task dotnet publish, which is not used to publish the nuget package. It used to create a .zip file archive that's ready for publishing to a web app:

Check the document Deploy a web app for some more details.

As test, you can view the content of that .zip:

enter image description here

To publish self-contained dotnet core package via pipeline UI to azure artifacts, you just need use the Copy task and PublishBuildArtifacts task.

The reason why it only pick up the contents of the "netcoreapp2.2" directory, that because you are not the correct syntax in the Contents in the copy task, it should be specify to the .nupkg:

 Contents: '**\bin\$(BuildConfiguration)\**\*.nupkg'

Then, in the artifacts:

enter image description here

Alternatively, we could specify the package folder to $(Build.ArtifactStagingDirectory) in the nuget pack task:

enter image description here

In this case, we do not need the copy task to copy package to the ArtifactStagingDirectory, just use task PublishBuildArtifacts.

Hope this helps.