Learn how to use the Telerik NuGet server, or NuGet packages with Azure Artifacts, in an Azure DevOps build pipeline.
As a Support Engineer, I frequently come across questions on how to use the Telerik NuGet server in Azure DevOps build pipelines. Since our NuGet server is a private feed that requires credentials, this can be confusing to set up the first time.
Let me help demystify this today by showing you two options you can use to restore Telerik NuGet packages in your build definitions.
- A Service Connection
- Azure Artifacts
Let's start with the more traditional approach and use the Service Connection and a nuget.config file to connect to the Telerik NuGet server to restore packages. Then, I'll explain how you host your own Telerik NuGet package(s) in an Azure Artifacts feed and restore packages from there instead.
In Visual Studio, you would add a private NuGet feed by going into the Tools > Options > NuGet > Package Sources and add a Package Source.
Visual Studio will prompt you for your Telerik credentials the first time the feed is accessed. These credentials can be later accessed via the Windows Credentials tab in the Credential Manager app (e.g. to update password).
However, what if your project is being built in an Azure DevOps build pipeline? How does the pipeline restore a package that is only in a private feed? This is where a NuGet config file comes into play. It allows you to set package sources as well as where to get the credentials.
Below is an example of a nuget.config file that will pull packages from the Telerik NuGet server. Notice the following important parts:
- The <packageSources> section. It contains a Telerik_NuGet package source, which points to the Telerik server's URL.
- The <packageSourceCredentials> section, it contains a child node with same name as one of the packageSources; "Telerik_NuGet". This is just one of the ways you can authenticate in an automated workflow (it is recommended that you use environment variables here, not readable text).
<?xml version="1.0" encoding="utf-8"?>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
<add key="All" value="(Aggregate source)" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="Telerik_NuGet" value="https://nuget.telerik.com/nuget" />
<!-- Use DevOps Service Connection instead of this section -->
<add key="Username" value="%TELERIK_USERNAME%" />
<add key="ClearTextPassword" value="%TELERIK_PASSWORD%" />
However, this could be a security issue in a CI/CD environment where another user might be able to read the values of environment variables that are not stored as secrets. This is where the Azure pipelines Service Connection
comes in handy.
The Azure DevOps Service Connection lets you enter credentials in a secure manner without unnecessarily exposing account details and that Service Connection can now be used by multiple pipelines to authenticate private NuGet feeds (and other services that need authentication).
In the following 4 minute video, I take you through the steps to set up the Service connection and how to use it in 3 different build Pipeline types:
- Adding a Service connection at 0:00
- Classic pipeline for .NET Core at 1:14
- Classic .NET Framework pipeline at 1:47
- YAML pipeline setup for .NET Core at 2:25
If you are a hands-on learner, you can see the real thing by going to my DevOps Demo on GitHub
. That repo is what I use in the video. You can click on the build badges and review the actual DevOps pipelines directly.
Service Connection Walkthrough
Let's walk through adding a Service Connection to the Telerik NuGet server. To start, go to the Project Settings in your DevOps project portal.
On the Project Settings page, select the Service Connections menu item under Pipelines and then open the New Service Connection drop down.
Select NuGet from the drop-down list.
You'll be presented with a dialog that lets you enter the URL and authentication credentials. For the Telerik NuGet server, you'll want to select Basic Authentication. Once that selection is made, you can enter the Telerik server URL and use your Telerik account credentials.
Once that is saved, your build pipelines can now fetch packages from the Telerik NuGet feed. Next, let's take a look at how a build pipeline uses the nuget.config and the Service Connection together to fetch the Telerik packages.
Using Telerik Service Connection
In your build pipeline, there's a NuGet Restore step. Select that step and look to the properties panel. Change the Feeds to Use selection to Feeds in my NuGet.config. A new drop-down will appear titled "Credentials for feeds outside this organization/collection." Open it and select the newly available Telerik NuGet Service Connection.
That's it! When you queue and run the pipeline, the Telerik NuGet packages will be restored.
Using a Service connection is our recommend approach. However there are scenarios where you don't have internet access in your DevOps environment (i.e. on-prem, high security) or you don't want the pipeline to be able to access other products in the Service connection.
In these cases, you can still restore from a feed, but it'll be an Azure Artifacts feed. In the project's main menu, select Artifacts and then click the New Feed button at the top.
Give the feed a name (e.g. TelerikPackages), select the "Only use packages published to this feed" option, then click the Create button. You will now have your own feed that you can push nupkg files to, or drag and drop on, and it will handle the heavy lifting of the server duties.
To see how to push packages to this feed, click the "Connect to feed" option at the top. A dialog will appear with helpful information on how you can push packages to that specific feed.
You can get the NuGet package file (nupkg) for any Telerik product you're using by going to the downloads page for that product. You can start at the My Account - All Products page.
Underneath the installer for the product, you'll see an Other Setup Files section where the nupkg files will be. For example, here's what it looks like for the Telerik Reporting packages.
The last piece of this puzzle is to go to the build pipeline and select that feed for a NuGet Restore step.
Using an Artifact Feed
Just like we did above for the Service Connection, go to the build pipeline and select the NuGet Restore step. Except this time, you'd choose Feed(s) I select here and choose the TelerikPackages feed in the Use packages from this Azure Artifacts/TFS feed drop-down list.
Important: If you have nuget.org packages to restore in addition to the Telerik packages, leave the "Use packages from NuGet.org" option selected.
I hope this information helps show how you can use Telerik NuGet packages in your Azure DevOps pipelines. you can take Service Connection route or go with a more controlled Azure Artifacts option.
You can find more information on using Azure DevOps or Azure Artifacts in the following documentation:
If you have any questions, don't hesitate to reach out. I'm available on Twitter @lancewmccarthy. If you're having problems with, or have questions about, the Telerik packages, you can talk directly to the engineers for that product by opening a Support Ticket.
Thanks for stopping by and have a great day!