Using Private NuGet Feeds in AppCenter

The Problem

Recently, I was working on a Xamarin.Forms project consuming a private NuGet feed. Because the account I use to log in to Visual Studio has permissions to consume that feed, I just added the feed address to Visual Studio and I could use it without any problems.

But when I tried to build my app in in CI/CD pipeline in AppCenter, it was unable to restore the packages because it didn’t have access, and the build failed with the following error message:

Unable to find package [x]. No packages exist with this id in the source(s): nuget.org
Unable to find package [x]. No packages exist with this id in the source(s): nuget.org

The Solution

One way to tell AppCenter where the feed is located is to add a nuget.config file in the same folder where the solution (.sln) file is and to include the following content (you will need to use your own URL).

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <add key="nuget.org" value="<https://api.nuget.org/v3/index.json>" />
        <add key="MyProject" value="<https://pkgs.dev.azure.com/myorganization/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/_packaging/MyProject/nuget/v3/index.json>" />
    </packageSources>
    <activePackageSource>
        <add key="All" value="(Aggregate source)" />
    </activePackageSource>
    <packageSourceCredentials>
        <MyProject>
            <add key="Username" value="%NUGET_USER%" />
            <add key="ClearTextPassword" value="%NUGET_PASSWORD%" />
        </MyProject>
    </packageSourceCredentials>
</configuration>

The %NUGET_USER% and %NUGET_PASSWORD% are parameters that I will later replace in AppCenter.

Next, I need to go to the account on Azure DevOps and create a Personal Access Token (PAT) used as the password. That will look something like this:

Creating a Personal Access Token (PAT)
Creating a Personal Access Token (PAT)

I will need to set a name, select the organization, and set the expiration date (up to one year). For the scope, I selected custom, with Packaging Read set. After creating the PAT, I must copy and safely store the PAT somewhere, because it will not be available anymore after closing the window.

Copy the token before closing the window
Copy the token before closing the window

The final step is to set the missing user and password parameters on AppCenter. For that, I create two environment variables that will be replaced on my nuget.config file when the branch is built.

Paste the PAT in as an environment variable
Paste the PAT in as an environment variable

The NUGET_USER is not required, but I like to specify it, so I could use it in the future if I want to, instead of a PAT. The NUGET_PASSWORD is the value of our PAT.

That’s all it takes! On our next build, AppCenter will be able to access the private Nuget feed and restore all of our packages.

Thanks for reading!

Picture of Rodrigo Juarez

Rodrigo Juarez

Rodrigo Juarez has over 25 years of experience in software development, specializing in Microsoft technologies. His mission is to solve complex problems for his clients, with a focus on results. He achieves this by applying the appropriate technology and using best practices to ensure the delivery of high-quality solutions. Over the past 6 years, Rodrigo has honed his skills in back-end development and in creating mobile applications, initially using Xamarin and now transitioning to .NET MAUI. He is a Lead Mobile Developer at Trailhead Technology Partners and the co-author, along with Jesse Liberty, of the book ".NET MAUI for C# Developers"

Free Consultation

Sign up for a FREE consultation with one of Trailhead's experts.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Related Blog Posts

We hope you’ve found this to be helpful and are walking away with some new, useful insights. If you want to learn more, here are a couple of related articles that others also usually find to be interesting:

Our Gear Is Packed and We're Excited to Explore With You

Ready to come with us? 

Together, we can map your company’s software journey and start down the right trails. If you’re set to take the first step, simply fill out our contact form. We’ll be in touch quickly – and you’ll have a partner who is ready to help your company take the next step on its software journey. 

We can’t wait to hear from you! 

Main Contact

This field is for validation purposes and should be left unchanged.

Together, we can map your company’s tech journey and start down the trails. If you’re set to take the first step, simply fill out the form below. We’ll be in touch – and you’ll have a partner who cares about you and your company. 

We can’t wait to hear from you! 

Thank you for reaching out.

You’ll be getting an email from our team shortly. If you need immediate assistance, please call (616) 371-1037.