Azure DevOps pipeline with Azure Artifact NuGet Feed for Dev environment

Tsuyoshi Ushio
3 min readApr 20, 2019

--

Sometimes, I want to create a private repository of NuGet. Especially, the library project, I can configure the NuGet Local repository, however, the problem is, if the library is the same version, it frequently hit the cache and point to the old version. Also, package -> copy the NuGet Local, Clear the local cache is tedious. I’d like to live lazy. These days, we can use Azure Artifact which host your own Repository like NuGet. It is very easy to configure that. I’ll share how to do it.

Create a feed of the Azure Artifact

Go to the Artifacts and create new feed. Just give it name and hit Create. Then you will see the new repository for NuGet Package.

Create new feed

Create a build pipeline

You might automate the build/pack/publish to NuGet.

Add VersionSuffix

For the development environment, we don’t want version up the semantic version, however, if we build a new build, we want to distinguish it by using BUILD_ID of the Azure DevOps. Let’s add $(VersionSuffix) on your csproj file, Version section.

<Version>0.0.1-alpha$(VersionSuffix)</Version>

For the production, it become blank since the $(VersionSuffix) is not set. however, for development environment, I’d like to make it like 0.0.1-alpha-21 0.0.1-alpha-22 and cleary change the name not for hit cache and update build everytime. 21 and 22 will be the BUILD_ID of the pipeline. If you add -alpha or -beta or -rc , it becomes pre-release.

The pipeline is almost the same as the template of Asp .NET Core. I change little bit for it.

Pipeline

Build

The point is, In case of build, you can specify the --version-suffix option with the parameter “-$(Build.BuildId)” It will overwrite the $(VersionSuffix) by the Build_ID of the CI pipeline.

Pack

Also, you need to add the Version Suffix on pack. If you are using GUI, you can go Advanced tab to configure it.

Nuget Push

BTW, I still prefer to start with classic GUI. It is very easy and eventually it can convert into yaml if necessary. Also, we can use template which is well defined. In this case, we can choose the Artifacts feed with drop down menu.

Now your Nuget Package is upload to the Artifacts

Nuget Push

Artifact

If you queue build, you will see the new version is upload to the Artifacts.

Feed

If you click Connect to feed, you can see the Connection information to this repo.

Connect to feed

Visual Studio

Configure the package source.

Then you will see all NuGet package for all build_id.

Package Manager

Conclusion

Creating a repository for Nuget Package is pretty easy with Azure DevOps. :)

This is the yaml for export from the pipeline.

--

--