abstract image of code

Visual Studio Code and Azure DevOps Artifacts

Are you using or wanting to use Visual Studio Code for work? Is your company using Azure DevOps and making use of private Artifact Feeds? If yes, you’ll need some setup in order to be able to authenticate successfully. Visual Studio 2019 has a convenient built in way of doing this, VS Code does not.

If you’ve already been using the tool and your PAT simply expired, you just need to create a new PAT in DevOps, then update the information below. Basically you need to update the area of your NuGet.Config, in Windows this is located in the %APPDATA%\NuGet folder.

      <add key="Username" value="{yourorganization}.pkgs.visualstudio.com\{username}" />
      <add key="ClearTextPassword" value="{yourPersonalAccessToken}" />

If you need to setup for the first time, then you’ll need this tool: Azure Artifacts Credential Provider. You’ll also need some other information and setup in your DevOps organization. As mentioned above you’ll need to create a Personal Access Token (PAT), as well as retrieve the URL for your Artifact feed.

Creating a PAT can be done by clicking your user profile icon when you’re logged into your DevOps site and clicking the ellipsis, then User settings, then Personal access tokens. Create a new token, give it a useful name, and copy the token that it provides. Finding the URL for the artifact feed can be done from the Project page in your DevOps site, by clicking the Artifacts item/icon in the project menu. At the top of that page, there will be a Connect to feed button that will provide you with multiple options like different IDEs and command line. For VS Code we’ll click the dotnet item listed near the top. The information you’ll need will be displayed in the Project setup area.

As mentioned on the Connect to feed page, your solution can have a nuget.config in source control. If, like me, you have multiple projects that use this feed, you can just add this information to your global nuget config as I mentioned above, that is located in %appdata%\NuGet on Windows.

Once the steps are complete, you should be able to enter dotnet restore --interactive into the command line from your solution folder. This will confirm your log in to your DevOps site and should be successful. This will also allow you as you continue working on your project to add new packages to your project without producing unauthorized 401 errors, which will prevent you from adding even normal public packages from nuget.com.

I hope you found this helpful! Happy coding.

Leave a Comment

Your email address will not be published. Required fields are marked *