🔥 Checkout our new Azure Developer page at azure.com/developer (opens new window).
📺 Watch the video : How to create, host, and share packages with Azure Artifacts (opens new window).
💡 Learn more : Azure Artifacts Documentation (opens new window)
# Create, host, and share packages with your team with Azure Artifacts
You probably use lots of packages in your applications. And you should, as there is lots of functionality available. You can use packages from a lot of sources, like NuGet, npm, Maven and more. But what if your team creates packages that you only want to use internally in your organization? Where do you host them securely and how do you share them? Azure Artifacts (opens new window) provides this capability. Azure Artifacts is a package feed that is part of Azure DevOps (opens new window). It allows you to host packages that you create and secure them for your organization. Let's take a look at how to create a package, host that on Azure Artifacts and use it in an application.
# 1. Create an Azure Artifacts feed
In order to host packages, we need to create a feed to host them on. We do that in the Azure DevOps portal.
- In the Azure DevOps portal (https://dev.azure.com')">, make sure that you have an organization and a project
- Now, in the Artifacts Menu, click on the New Feed button
(Create a new Azure Artifacts feed)
- Fill in a Name for the feed and pick the options that you like. When you choose to Use packages from public sources through this feed, you can use this feed to also get packages from feeds like nuget.org. The benefit that this creates is that developers only have to connect to one feed (your feed) to get their packages and once a package is used, it will be copied to your feed and stored there. So even if the package is removed from the public feed or if the public feed goes down, you can still use it
(Select the details for the feed)
- Click Create to create the feed
- In the screen that pops up now, download the tools (step 1 in the image below) and execute the command in step 2 in a command window in the folder of the files that you download in step 1. The command will ask you to log in to use the feed. This will add the feed to to your NuGet configuration, so that when you use a package from there (for instance in Visual Studio), it will allow you to use packages from your feed
(Add the feed to the NuGet configuration)
That's it! We now have a feed that we can use to host packages on.
# 2. Create a package in Visual Studio and publish it to the feed
Now that we have the feed, we can start putting packages on it. We'll do that using Visual Studio. In Visual Studio, I've created a console application (ConsoleApp1) and a .NET Standard library (MyFirstPackage). In the library, I've added a simple class that has a method that returns a string. We'll create a NuGet package from the library and publish that to our Azure Artifacts feed.
- In Visual Studio, right-click the library project and click Pack. This will create a NuGet package from the library
- You can customize the properties of the NuGet package by editing the values in the Package tab of the project properties (right-click the project and click Properties)
(Create a NuGet package in Visual Studio)
- You can find the NuGet package in the bin > Debug folder of the project (because the project configuration is currently set to Debug). The file will have a .nupkg extension
- Navigate to a commandline that has access to the NuGet command. You can also use the NuGet.exe file that you've downloaded when you've connected to the feed. Now publish the package to the feed using this command:
nuget.exe push -Source "https://pkgs.dev.azure.com/azuretandt/_packaging/mypackages/nuget/v3/index.json" -ApiKey key "C:\Users\Michael\source\repos\ConsoleApp1\ClassLibrary1\bin\Debug\MyFirstPackage.2.3.0.nupkg"
Make sure that you replace the URL of your feed and the path to your package file. The command might ask you to log in again and it will push the package to your feed.
You can leave the ApiKey value to an arbitrary value, like "key". This parameter is needed because we're using nuget.exe. When you push a package to nuget.org, this value needs to have an actual key value in it.
(Publish the package to the Azure Artifacts feed)
# 3. Use a package from the Azure Artifacts feed
We now have a private package feed with a package on it that we've created ourselves. Now, we can use the feed and the package on it.
- In Visual Studio 2019, in the ConsoleApp1 project, right-click the project and click Manage NuGet Packages
- In the NuGet screen, you can now navigate to the Package source of your feed, so MyPackages2 in my case. You might have to log in to authenticate yourself to the feed
- Here, you'll find all of your packages, like the package that we've just created and uploaded. You can now install it, update it, uninstall it and use it like any other package that you would use
(Use the package from our private feed)
Azure Artifacts is a great way to host and share your packages with. You can build a big library of things that you use regularly in you organization and share them amongst your teams. The first 5 users can use Azure Artifacts for free. Additional users have to purchase Azure Artifacts licenses to access the feeds and publish packages on them. Go and check it out!