Installing the credentials provider

You’ll need to install credentials provider for the interactive authentication. This can be downloaded here. I’d recommend using the Powershell script which can be downloaded from the Github repository. You may require to allow execution of this Powershell script as shown below, don’t forget to revert it to whatever you were using previously.

Set-ExecutionPolicy Unrestricted

The default execution policy is ‘Undefined’.

Generating a Personal Access Token (PAT)

Read the documentation below to generate a personal access token.

https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page

Building the package

First we’ll have to set a version or increment the version of the assembly. To do this, open ‘Visual Studio’, and in ‘Solution Explorer‘, right-click your project and choose ‘Properties‘. Then navigate to the ‘Package‘ tab where you can set the ‘Package version‘.

In ‘Visual Studio’, and make sure ‘Solution Explorer‘ is open. Then just right-click your project and choose ‘Pack‘.

Publishing the package

[Publish a NuGet package using the command line – Azure Artifacts Microsoft Docs](https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/publish?view=azure-devops)

You’ll have to put a ‘nuget.config’ file with the feed’s name in your project directory.

dotnet nuget push --source "MyFeed" --api-key yourkeygoeshere .\bin\Release\My.First.NuGet.1.0.0.nupkg --interactive

The ‘–interactive’ flag might only be required the first time.

Note

Ideally you want a GitFlow-like way of working and create a release pipeline for publishing the package from your main branch. This avoids that developers are publishing a NuGet package before their code is actually approved and merged into the main branch for use by other team members.