NuGet.Packaging 6.14.0

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
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
111
Microsoft.DotNet.Cli.Utils
Package Description
105
Microsoft.DotNet.Cli.Utils
Package Description
102
Microsoft.DotNet.Cli.Utils
Microsoft.DotNet.Cli.Utils
96
Microsoft.DotNet.Scaffolding.Shared
Contains interfaces for Project Model and messaging for scaffolding.
95
Microsoft.DotNet.Cli.Utils
Package Description
93
NuGet.Protocol
NuGet client library.
92
Microsoft.DotNet.Cli.Utils
Package Description
92
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
92
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging. Contains only the type forwarders to the new assembly.
92
NuGet.Protocol
NuGet client library.
91
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging. Contains only the type forwarders to the new assembly.
91
Microsoft.DotNet.Scaffolding.Shared
Contains interfaces for Project Model and messaging for scaffolding.
91
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging.
90
Microsoft.DotNet.ProjectModel
Types to model a .NET Project
90
Microsoft.VisualStudio.Web.CodeGenerators.Mvc
Code Generators for ASP.NET Core MVC. Contains code generators for MVC Controllers and Views.
90
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
89

.NET Framework 4.7.2

.NET 8.0

.NET Standard 2.0

Version Downloads Last updated
6.14.0 36 5/15/2025
6.13.2 48 2/28/2025
6.13.1 65 2/14/2025
6.12.4 55 5/9/2025
6.12.1 57 11/17/2024
6.12.0 47 11/19/2024
6.11.1 52 10/6/2024
6.11.0 53 8/15/2024
6.11.0-preview.2 55 6/5/2024
6.10.2 59 8/15/2024
6.10.1 54 6/28/2024
6.10.0 49 6/5/2024
6.9.1 60 2/23/2024
6.8.1 62 2/21/2024
6.8.0 64 11/18/2023
6.7.1 58 2/23/2024
6.7.0 90 8/18/2023
6.6.2 58 2/23/2024
6.6.1 94 7/30/2023
6.6.0 64 5/20/2023
6.6.0-preview.3 63 5/20/2023
6.5.1 61 7/21/2023
6.5.0 66 2/24/2023
6.4.3 54 2/21/2024
6.4.2 90 8/4/2023
6.4.0 72 12/6/2022
6.3.4 67 2/23/2024
6.3.3 66 8/4/2023
6.3.1 73 11/14/2022
6.3.0 77 9/17/2022
6.2.4 70 8/4/2023
6.2.2 65 11/16/2022
6.2.1 73 6/30/2022
6.2.0 71 6/30/2022
6.1.0 70 6/30/2022
6.0.6 59 2/23/2024
6.0.5 64 8/4/2023
6.0.3-rc.1 66 11/25/2022
6.0.2 91 6/30/2022
6.0.0 72 6/30/2022
6.0.0-preview.4.243 72 6/30/2022
6.0.0-preview.3 67 6/30/2022
5.11.6 58 2/23/2024
5.11.5 66 8/1/2023
5.11.3 90 10/13/2022
5.11.2 82 6/30/2022
5.11.0 73 6/30/2022
5.10.0 89 6/30/2022
5.10.0-preview.2.7185 59 6/30/2022
5.9.3 79 11/25/2022
5.9.2 83 6/30/2022
5.9.1 87 6/30/2022
5.9.0 78 6/30/2022
5.9.0-preview.2 66 6/30/2022
5.8.1 89 6/30/2022
5.8.0 86 6/30/2022
5.8.0-preview.3.6823 60 6/30/2022
5.8.0-preview.2.6776 60 6/30/2022
5.8.0-preview.1 102 6/30/2022
5.7.3-rtm.5 66 12/7/2022
5.7.2 77 6/30/2022
5.7.1 64 6/30/2022
5.7.0 65 6/30/2022
5.7.0-rtm.6702 69 6/30/2022
5.7.0-preview.3.6653 79 6/30/2022
5.7.0-preview.2.6618 65 6/30/2022
5.7.0-preview.1.6592 63 6/30/2022
5.6.0 75 6/30/2022
5.6.0-preview.3.6558 77 6/30/2022
5.6.0-preview.2.6489 74 6/30/2022
5.6.0-preview.1.6483 67 6/30/2022
5.5.1 65 6/30/2022
5.5.0 72 6/30/2022
5.5.0-preview.2.6382 84 6/30/2022
5.5.0-preview.1.6319 71 6/30/2022
5.4.0 66 6/30/2022
5.3.1 88 6/30/2022
5.3.0 71 6/30/2022
5.3.0-rtm.6192 74 6/30/2022
5.2.1 72 6/30/2022
5.2.0 82 6/30/2022
5.1.0 87 6/30/2022
5.1.0-preview2.5965 63 6/30/2022
5.0.2 101 6/30/2022
5.0.0 78 6/30/2022
5.0.0-rtm.5867 62 6/30/2022
5.0.0-rtm.5856 63 6/30/2022
5.0.0-preview3.5800 71 6/30/2022
5.0.0-preview2.5782 67 6/30/2022
4.9.6 111 10/13/2022
4.9.5 67 6/30/2022
4.9.4 87 6/30/2022
4.9.3 91 6/30/2022
4.9.2 69 6/30/2022
4.9.2-rtm.5706 71 6/30/2022
4.9.1 66 6/30/2022
4.9.0-rtm.5658 64 6/30/2022
4.8.2 70 6/30/2022
4.8.0 98 6/30/2022
4.8.0-rtm.5362 65 6/30/2022
4.8.0-preview3.5278 74 6/30/2022
4.8.0-preview1.5156 62 6/30/2022
4.7.3 82 6/30/2022
4.7.2 69 6/30/2022
4.7.0 91 6/30/2022
4.7.0-rtm.5148 60 6/30/2022
4.7.0-rtm.5104 70 6/30/2022
4.7.0-preview4.5065 66 6/30/2022
4.7.0-preview1-4986 66 6/30/2022
4.6.4 78 6/30/2022
4.6.3 64 6/30/2022
4.6.2 64 6/30/2022
4.6.1 102 6/30/2022
4.6.0 81 6/30/2022
4.6.0-rtm-4918 53 6/30/2022
4.6.0-rtm-4825 66 6/30/2022
4.6.0-rtm-4791 69 6/30/2022
4.5.3 99 6/30/2022
4.5.2 63 6/30/2022
4.5.0 93 6/30/2022
4.5.0-rtm-4651 60 6/30/2022
4.4.3 67 6/30/2022
4.4.2 66 6/30/2022
4.4.0 70 6/30/2022
4.4.0-preview3-4475 105 6/30/2022
4.3.1 106 6/30/2022
4.3.0 115 6/30/2022
4.3.0-rtm-4324 68 6/30/2022
4.3.0-preview4 67 6/30/2022
4.3.0-preview3-4168 60 6/30/2022
4.3.0-beta1-2418 91 6/30/2022
4.2.0 64 6/30/2022
4.1.0 68 6/30/2022
4.0.0 63 6/30/2022
4.0.0-rtm-2283 67 6/30/2022
4.0.0-rtm-2265 68 6/30/2022
4.0.0-rc3 79 6/30/2022
4.0.0-rc2 92 6/30/2022
4.0.0-rc-2048 65 6/30/2022
3.5.0 70 6/30/2022
3.5.0-rc1-final 62 6/30/2022
3.5.0-beta2-1484 64 6/30/2022
3.5.0-beta-final 75 6/30/2022
3.4.4-rtm-final 69 6/30/2022
3.4.4-rc 75 6/30/2022
3.4.3 69 6/29/2022
3.3.0 83 6/29/2022
3.2.0 67 6/29/2022
1.0.0-pre-20150220044603 80 6/29/2022
1.0.0-pre-20150128082032 59 6/29/2022
1.0.0-pre-20150128071326 62 6/29/2022
1.0.0-pre-20150127085617 72 6/29/2022
1.0.0-pre-20150127072405 61 6/29/2022
1.0.0-pre-20150120213149 82 6/29/2022
1.0.0-pre-20150120004808 63 6/29/2022
1.0.0-pre-20150115030027 84 6/29/2022
1.0.0-pre-20150109221036 92 6/29/2022
1.0.0-pre-20150108074227 68 6/29/2022
1.0.0-pre-20150108073125 78 6/29/2022
1.0.0-pre-20150108010629 65 6/29/2022
1.0.0-master-50072333 69 6/29/2022
1.0.0-master-50060114 55 6/29/2022
1.0.0-master-50050213 71 6/29/2022
1.0.0-master-43652058 59 6/29/2022
1.0.0-master-43642026 71 6/29/2022
1.0.0-master-43522145 66 6/29/2022
1.0.0-master-43500148 65 6/29/2022
1.0.0-master-43450313 62 6/29/2022
1.0.0-master-43440912 62 6/29/2022
1.0.0-master-43422320 65 6/29/2022
1.0.0-master-43421050 86 6/29/2022
1.0.0-master-43421019 63 6/29/2022
1.0.0-master-43402220 74 6/29/2022
1.0.0-master-43362332 66 6/29/2022
1.0.0-master-43362323 67 6/29/2022
1.0.0-master-43250244 70 6/29/2022
1.0.0-master-43250241 80 6/29/2022
1.0.0-master-43250237 64 6/29/2022
1.0.0-master-43250218 90 6/29/2022
1.0.0-juste-43290204 83 6/29/2022