Using Private NuGet Feeds with .NET MAUI and Azure Pipelines

As you may already know, there’s no App Center support for .NET MAUI yet (and possibly won’t be). Trailhead is using Azure Pipelines for many of our projects, including for generating our mobile builds and distributing them to the app stores (Apple and Android).

One of the challenges when you do this is bringing in private NuGet packages from a private feed. In this blog, we’ll review everything to take into account to be able to use a private NuGet feed with Azure Pipelines.

General steps

1. Create a Personal Access Token.

  • Go to User settings (on the top-right menu on Azure DevOps) > Personal access token.
  • Create the Personal access token.
  • Copy the token, we’ll use in the next step.

2. Create a nuget.config file.

  • See the reference in this blog, we’ll create the nuget.config file with this content. You can replace:
    • YOUR_USERNAME with the username you prefer, this username will be used in the Android steps.
    • YOUR_PASSWORD with the token created previously.
    • MyProject: the name of your private NuGet feed.
<?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="YOUR_USERNAME" />
            <add key="ClearTextPassword" value="YOUR_PASSWORD" />
        </MyProject>
    </packageSourceCredentials>
</configuration>

3. Add the nuget.config to the root of the project.

iOS Config

Surprise! There are no more steps to perform for iOS. So, you can update the branch where you define your yml.file with this change and run it.

Android Config

To get this working for your Android build, follow these steps:

1. Go to Azure Project settings > Pipelines – Service connections

2. Add a new service connection, look for Nuget, and click Next.

3. Select Basic Authentication

  • Feed URL: replace with the URL you use to create your nuget.config file. Example: https://pkgs.dev.azure.com/myorganization/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/_packaging/MyProject/nuget/v3/index.json.
  • Username: replace with YOUR_USERNAME set in General Steps – 2.
  • Password: replace with YOUR_PASSWORD set in General Steps – 2.
  • Service connection name: the name of your private feed. This example will be MyProject.

Select the Grant access permission to all pipelines option and Save.

4. Update the yml.file

  • Make sure to set the Task CmdLine@2 before the NuGet tasks.
  • Replace ‘MyProject’ with the name of your private feed (in NuGetAuthenticate@1 and NuGetCommand@2).
  • Replace restoreSolution (in NuGetCommand@2) with the Path to solution. For this example will be ‘*.sln‘.
...
steps:
- task: UseDotNet@2
  displayName: 'Install .NET sdk'
  inputs:
    packageType: sdk
    version: $(DotNetVersion)
    installationPath: $(Agent.ToolsDirectory)/dotnet

- task: CmdLine@2
  displayName: 'Install Maui Workload'
  inputs:
    script: 'dotnet workload install maui'

- task: NuGetAuthenticate@1
  inputs:
    nuGetServiceConnections: 'MyProject'

- task: NuGetToolInstaller@1
  displayName: Use Nuget 6.6.1
  inputs:
    versionSpec: 6.x

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'
    externalFeedCredentials: 'MyProject'
...

Conclusion

Using a private NuGet feed with Azure Pipelines for your .NET MAUI projects is essential for managing and distributing your private packages into your cross-platform mobile projects efficiently. In this blog, we’ve walked through all the necessary steps to set this up for both Android and iOS builds. I hope this guide has been helpful in demystifying this process!

References

  • NuGetCommand@2: link

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! 

Montage Portal

Montage Furniture Services provides furniture protection plans and claims processing services to a wide selection of furniture retailers and consumers.

Project Background

Montage was looking to build a new web portal for both Retailers and Consumers, which would integrate with Dynamics CRM and other legacy systems. The portal needed to be multi tenant and support branding and configuration for different Retailers. Trailhead architected the new Montage Platform, including the Portal and all of it’s back end integrations, did the UI/UX and then delivered the new system, along with enhancements to DevOps and processes.

Logistics

We’ve logged countless miles exploring the tech world. In doing so, we gained the experience that enables us to deliver your unique software and systems architecture needs. Our team of seasoned tech vets can provide you with:

Custom App and Software Development

We collaborate with you throughout the entire process because your customized tech should fit your needs, not just those of other clients.

Cloud and Mobile Applications

The modern world demands versatile technology, and this is exactly what your mobile and cloud-based apps will give you.

User Experience and Interface (UX/UI) Design

We want your end users to have optimal experiences with tech that is highly intuitive and responsive.

DevOps

This combination of Agile software development and IT operations provides you with high-quality software at reduced cost, time, and risk.

Trailhead stepped into a challenging project – building our new web architecture and redeveloping our portals at the same time the business was migrating from a legacy system to our new CRM solution. They were able to not only significantly improve our web development architecture but our development and deployment processes as well as the functionality and performance of our portals. The feedback from customers has been overwhelmingly positive. Trailhead has proven themselves to be a valuable partner.

– BOB DOERKSEN, Vice President of Technology Services
at Montage Furniture Services

Technologies Used

When you hit the trails, it is essential to bring appropriate gear. The same holds true for your digital technology needs. That’s why Trailhead builds custom solutions on trusted platforms like .NET, Angular, React, and Xamarin.

Expertise

We partner with businesses who need intuitive custom software, responsive mobile applications, and advanced cloud technologies. And our extensive experience in the tech field allows us to help you map out the right path for all your digital technology needs.

  • Project Management
  • Architecture
  • Web App Development
  • Cloud Development
  • DevOps
  • Process Improvements
  • Legacy System Integration
  • UI Design
  • Manual QA
  • Back end/API/Database development

We partner with businesses who need intuitive custom software, responsive mobile applications, and advanced cloud technologies. And our extensive experience in the tech field allows us to help you map out the right path for all your digital technology needs.

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

Ready to come with us? 

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 contact form. 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.