NuGet.Packaging 6.9.1

Nuget.Packaging

NuGet.Packaging is a NuGet client SDK library that provides a set of APIs to interact with .nupkg and .nuspec files from a stream. It provides a way for developers to create and read packages and work with the package metadata.

Usage

It is strongly recommended that NuGet packages are created using the official NuGet tooling and instead of this low-level API. There are a variety of characteristics important for a well-formed package and the latest version of tooling helps incorporate these best practices.

For more information about creating NuGet packages, see the overview of the package creation workflow and the documentation for official pack tooling (for example, using the dotnet CLI).

Examples

Create a package

Create a package, set metadata, and add dependencies.

PackageBuilder builder = new PackageBuilder();
builder.Id = "MyPackage";
builder.Version = new NuGetVersion("1.0.0-beta");
builder.Description = "My package created from the API.";
builder.Authors.Add("Sample author");
builder.DependencyGroups.Add(new PackageDependencyGroup(
    targetFramework: NuGetFramework.Parse("netstandard1.4"),
    packages: new[]
    {
        new PackageDependency("Newtonsoft.Json", VersionRange.Parse("10.0.1"))
    }));

using FileStream outputStream = new FileStream("MyPackage.nupkg", FileMode.Create);
builder.Save(outputStream);
Console.WriteLine($"Saved a package to {outputStream.Name}");

Read a package

Read a package from a file.

using FileStream inputStream = new FileStream("MyPackage.nupkg", FileMode.Open);
using PackageArchiveReader reader = new PackageArchiveReader(inputStream);
NuspecReader nuspec = reader.NuspecReader;
Console.WriteLine($"ID: {nuspec.GetId()}");
Console.WriteLine($"Version: {nuspec.GetVersion()}");
Console.WriteLine($"Description: {nuspec.GetDescription()}");
Console.WriteLine($"Authors: {nuspec.GetAuthors()}");

Console.WriteLine("Dependencies:");
foreach (PackageDependencyGroup dependencyGroup in nuspec.GetDependencyGroups())
{
    Console.WriteLine($" - {dependencyGroup.TargetFramework.GetShortFolderName()}");
    foreach (var dependency in dependencyGroup.Packages)
    {
        Console.WriteLine($"   > {dependency.Id} {dependency.VersionRange}");
    }
}

Additional documentation

More information about the NuGet.Packaging library can be found on the official Microsoft documentation page and NuGet API docs.

Showing the top 20 packages that depend on NuGet.Packaging.

Packages Downloads
Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
Contains Entity Framework Core Services used by ASP.NET Core Code Generators.
36
Microsoft.DotNet.Cli.Utils
Package Description
34
Microsoft.VisualStudio.Web.CodeGeneration.Utils
Contains utilities used by ASP.NET Core Code Generation packages.
34
Microsoft.DotNet.ProjectModel
Types to model a .NET Project
31
Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
Contains Entity Framework Core Services used by ASP.NET Core Code Generators.
31
Microsoft.VisualStudio.Web.CodeGeneration.Core
Contains the core infrastructure used by ASP.NET Core Code Generators.
31
NuGet.Protocol
NuGet client library.
30
NuGet.Protocol
NuGet's implementation for interacting with feeds. Contains functionality for all feed types.
30
Microsoft.VisualStudio.Web.CodeGeneration
Contains the CodeGenCommand that finds the appropriate code generator and invokes it from project dependencies.
30
Microsoft.DotNet.Scaffolding.Shared
Contains interfaces for Project Model and messaging for scaffolding.
30
Microsoft.DotNet.Cli.Utils
Microsoft.DotNet.Cli.Utils
29
NuGet.Protocol
NuGet client library.
29
Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
Contains Entity Framework Core Services used by ASP.NET Core Code Generators.
29
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
28
Microsoft.VisualStudio.Web.CodeGeneration.Templating
Contains Razor based templating host used by ASP.NET Core Code Generators.
28
Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
Contains Entity Framework Core Services used by ASP.NET Core Code Generators.
28
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging. Contains only the type forwarders to the new assembly.
27
NuGet.Protocol
NuGet client library.
27

.NET Framework 4.7.2

.NET 5.0

.NET Standard 2.0

Version Downloads Last updated
6.9.1 9 2/23/2024
6.8.1 9 2/21/2024
6.8.0 14 11/18/2023
6.7.1 11 2/23/2024
6.7.0 16 8/18/2023
6.6.2 8 2/23/2024
6.6.1 16 7/30/2023
6.6.0 14 5/20/2023
6.6.0-preview.3 15 5/20/2023
6.5.1 13 7/21/2023
6.5.0 13 2/24/2023
6.4.3 9 2/21/2024
6.4.2 16 8/4/2023
6.4.0 19 12/6/2022
6.3.4 9 2/23/2024
6.3.3 17 8/4/2023
6.3.1 20 11/14/2022
6.3.0 22 9/17/2022
6.2.4 17 8/4/2023
6.2.2 14 11/16/2022
6.2.1 23 6/30/2022
6.2.0 19 6/30/2022
6.1.0 20 6/30/2022
6.0.6 8 2/23/2024
6.0.5 14 8/4/2023
6.0.3-rc.1 20 11/25/2022
6.0.2 18 6/30/2022
6.0.0 22 6/30/2022
6.0.0-preview.4.243 22 6/30/2022
6.0.0-preview.3 20 6/30/2022
5.11.6 11 2/23/2024
5.11.5 13 8/1/2023
5.11.3 20 10/13/2022
5.11.2 23 6/30/2022
5.11.0 21 6/30/2022
5.10.0 18 6/30/2022
5.10.0-preview.2.7185 19 6/30/2022
5.9.3 15 11/25/2022
5.9.2 26 6/30/2022
5.9.1 22 6/30/2022
5.9.0 19 6/30/2022
5.9.0-preview.2 18 6/30/2022
5.8.1 20 6/30/2022
5.8.0 20 6/30/2022
5.8.0-preview.3.6823 20 6/30/2022
5.8.0-preview.2.6776 20 6/30/2022
5.8.0-preview.1 24 6/30/2022
5.7.3-rtm.5 20 12/7/2022
5.7.2 21 6/30/2022
5.7.1 18 6/30/2022
5.7.0 16 6/30/2022
5.7.0-rtm.6702 22 6/30/2022
5.7.0-preview.3.6653 24 6/30/2022
5.7.0-preview.2.6618 24 6/30/2022
5.7.0-preview.1.6592 22 6/30/2022
5.6.0 16 6/30/2022
5.6.0-preview.3.6558 20 6/30/2022
5.6.0-preview.2.6489 30 6/30/2022
5.6.0-preview.1.6483 21 6/30/2022
5.5.1 16 6/30/2022
5.5.0 21 6/30/2022
5.5.0-preview.2.6382 25 6/30/2022
5.5.0-preview.1.6319 22 6/30/2022
5.4.0 18 6/30/2022
5.3.1 23 6/30/2022
5.3.0 16 6/30/2022
5.3.0-rtm.6192 22 6/30/2022
5.2.1 17 6/30/2022
5.2.0 22 6/30/2022
5.1.0 24 6/30/2022
5.1.0-preview2.5965 20 6/30/2022
5.0.2 17 6/30/2022
5.0.0 20 6/30/2022
5.0.0-rtm.5867 21 6/30/2022
5.0.0-rtm.5856 18 6/30/2022
5.0.0-preview3.5800 26 6/30/2022
5.0.0-preview2.5782 21 6/30/2022
4.9.6 24 10/13/2022
4.9.5 18 6/30/2022
4.9.4 16 6/30/2022
4.9.3 26 6/30/2022
4.9.2 20 6/30/2022
4.9.2-rtm.5706 25 6/30/2022
4.9.1 16 6/30/2022
4.9.0-rtm.5658 19 6/30/2022
4.8.2 21 6/30/2022
4.8.0 25 6/30/2022
4.8.0-rtm.5362 18 6/30/2022
4.8.0-preview3.5278 30 6/30/2022
4.8.0-preview1.5156 21 6/30/2022
4.7.3 20 6/30/2022
4.7.2 19 6/30/2022
4.7.0 25 6/30/2022
4.7.0-rtm.5148 16 6/30/2022
4.7.0-rtm.5104 19 6/30/2022
4.7.0-preview4.5065 18 6/30/2022
4.7.0-preview1-4986 18 6/30/2022
4.6.4 16 6/30/2022
4.6.3 17 6/30/2022
4.6.2 17 6/30/2022
4.6.1 21 6/30/2022
4.6.0 18 6/30/2022
4.6.0-rtm-4918 14 6/30/2022
4.6.0-rtm-4825 18 6/30/2022
4.6.0-rtm-4791 26 6/30/2022
4.5.3 17 6/30/2022
4.5.2 11 6/30/2022
4.5.0 22 6/30/2022
4.5.0-rtm-4651 16 6/30/2022
4.4.3 15 6/30/2022
4.4.2 19 6/30/2022
4.4.0 19 6/30/2022
4.4.0-preview3-4475 33 6/30/2022
4.3.1 26 6/30/2022
4.3.0 36 6/30/2022
4.3.0-rtm-4324 22 6/30/2022
4.3.0-preview4 17 6/30/2022
4.3.0-preview3-4168 18 6/30/2022
4.3.0-beta1-2418 31 6/30/2022
4.2.0 16 6/30/2022
4.1.0 14 6/30/2022
4.0.0 15 6/30/2022
4.0.0-rtm-2283 24 6/30/2022
4.0.0-rtm-2265 23 6/30/2022
4.0.0-rc3 29 6/30/2022
4.0.0-rc2 26 6/30/2022
4.0.0-rc-2048 23 6/30/2022
3.5.0 17 6/30/2022
3.5.0-rc1-final 22 6/30/2022
3.5.0-beta2-1484 24 6/30/2022
3.5.0-beta-final 22 6/30/2022
3.4.4-rtm-final 23 6/30/2022
3.4.4-rc 20 6/30/2022
3.4.3 21 6/29/2022
3.3.0 23 6/29/2022
3.2.0 16 6/29/2022
1.0.0-pre-20150220044603 27 6/29/2022
1.0.0-pre-20150128082032 20 6/29/2022
1.0.0-pre-20150128071326 18 6/29/2022
1.0.0-pre-20150127085617 23 6/29/2022
1.0.0-pre-20150127072405 20 6/29/2022
1.0.0-pre-20150120213149 26 6/29/2022
1.0.0-pre-20150120004808 20 6/29/2022
1.0.0-pre-20150115030027 27 6/29/2022
1.0.0-pre-20150109221036 26 6/29/2022
1.0.0-pre-20150108074227 19 6/29/2022
1.0.0-pre-20150108073125 23 6/29/2022
1.0.0-pre-20150108010629 21 6/29/2022
1.0.0-master-50072333 26 6/29/2022
1.0.0-master-50060114 17 6/29/2022
1.0.0-master-50050213 22 6/29/2022
1.0.0-master-43652058 19 6/29/2022
1.0.0-master-43642026 15 6/29/2022
1.0.0-master-43522145 22 6/29/2022
1.0.0-master-43500148 21 6/29/2022
1.0.0-master-43450313 17 6/29/2022
1.0.0-master-43440912 19 6/29/2022
1.0.0-master-43422320 20 6/29/2022
1.0.0-master-43421050 31 6/29/2022
1.0.0-master-43421019 20 6/29/2022
1.0.0-master-43402220 15 6/29/2022
1.0.0-master-43362332 25 6/29/2022
1.0.0-master-43362323 24 6/29/2022
1.0.0-master-43250244 23 6/29/2022
1.0.0-master-43250241 20 6/29/2022
1.0.0-master-43250237 20 6/29/2022
1.0.0-master-43250218 30 6/29/2022
1.0.0-juste-43290204 27 6/29/2022