Consume VSTS hosted NuGet packages in VS Code

Recently, I started using NuGet package hosting in Visual Studio Team Services. I quickly found that in order to consume those packages in Visual Studio Code on my mac, I had to perform a few extra steps outside of simply connecting to the package url, which I’ve outlined here.

  1. If you haven’t already done so, install the dotnet sdk
  2. Login to VSTS and navigate to the User menu > Security option:
  3. Create a Personal Access Token (PAT):
      • Enter a description for the token
      • Set the expiration to 1 year
      • Ensure the selected account is correct
      • Set either of the following Authorized Scopes:
        • Packaging (read and write)
        • Packaging (read)
      • Click the Create Token button
  4. On the Personal Access Tokens window, copy the PAT value:
  5. From a terminal, enter the following command:
    nuget sources add -Name <YOUR_REPO_NAME> -Source <YOUR_REPO_SOURCE_URL> -UserName <YOUR_EMAIL_ADDRESS> -Password <PAT_VALUE> -StorePasswordInClearText -ConfigFile ~/.nuget/NuGet/NuGet.Config
  6. After the command completes, you should see the following output:
    Package Source with Name: <YOUR_REPO_NAME> added successfully.

After you’ve performed these steps, you should be able to successfully install and restore your custom NuGet packages from your VSTS repo.