Recently I participated in a project where we had some datamodels, which we had to share between different applications and parts of a system. We collected these models in their own c# library projects.

After that we wanted it to work in such a way that if the models were updated and the source code commited, they should be rebuilt and published to our Azure Artifacts Library. These nuget packages should then be included in the necessary projects.

I am writing this article to remind myself how i did this and also share this info with others on the internet.

To get started u need before u start:

  • A solution with a class library project which is ready for packing
  • A repository in Azure DevOps
  • Created feed under the Artifacts page like this:
feed creation settings
In the artifacts permissions part, delete the Software Build Service and then add it again with the contributer role when u create your build pipeline.

These are the steps to follow to create your pipeline:

Go to pipelines in your Azure DevOps environment for your software.

Select “New Pipeline” in the upper right corner.

Select your repository source type in this case it was Azure Repos Git.

Then select “Use classic editor” in the bottom of the list.

Then choose the repo that u will be making the package for.

Create a .net core build pipeline from the Template.

Keep the restore task as it is.

To the build task add the argument: /p:Version=$(Build.BuildNumber) to the Arguments parameter –-configuration $(BuildConfiguration) --no-restore, so that it ends up like this:

--configuration $(BuildConfiguration) --no-restore /p:Version=$(Build.BuildNumber)

Edit the default Test step to a Pack step by renaming it and selecting pack in the command * field.

Select “Use the build number” in Pack options

Copy the Pack task by right clicking on it and rename it to Push and select the command “Nuget Push” in the dropdown.

In the Push step select your required Target feed.

Keep the Publish and Publish Artifacts if u also want to access the build in Azure download.

This is the resulting pipeline:

Voila! Now it should be possible for you to create nugetpackage of your libraries when u build. Beware that it is not possible to push nuget packages from a release pipeline.

Last modified: March 29, 2023

Author

Comments

Write a Reply or Comment

Your email address will not be published.