NuGet.Packaging 7.6.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
178
Microsoft.DotNet.Cli.Utils
Package Description
164
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
153
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging.
151
NuGet.Protocol
NuGet's implementation for interacting with feeds. Contains functionality for all feed types.
151
NuGet.Protocol
NuGet client library.
150
Microsoft.DotNet.Scaffolding.Shared
Contains interfaces for Project Model and messaging for scaffolding.
150
NuGet.Protocol
NuGet client library.
149
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging. Contains only the type forwarders to the new assembly.
149
Microsoft.DotNet.Cli.Utils
Package Description
147
NuGet.Packaging.Core
The (former home to) core data structures for NuGet.Packaging. Contains only the type forwarders to the new assembly.
146
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
145
Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
Contains Entity Framework Core Services used by ASP.NET Core Code Generators.
144
Microsoft.DotNet.Cli.Utils
Microsoft.DotNet.Cli.Utils
144
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
143
NuGet.Protocol
NuGet client library.
143
NuGet.Protocol.Core.Types
NuGet's protocol-level base types used for connecting to API v2 and API v3 repositories.
143
NuGet.Protocol.Core.v3
NuGet Protocol for 3.1.0 servers
142
Microsoft.DotNet.Scaffolding.Shared
Contains interfaces for Project Model and messaging for scaffolding.
142
Microsoft.DotNet.ProjectModel
Types to model a .NET Project
142

.NET Framework 4.7.2

.NET 8.0

Version Downloads Last updated
7.6.0 14 5/13/2026
7.3.1 10 5/3/2026
7.3.0 20 2/18/2026
7.0.3 14 5/3/2026
7.0.1 41 11/25/2025
7.0.0 54 11/12/2025
6.14.3 15 5/3/2026
6.14.0 81 5/15/2025
6.13.2 98 2/28/2025
6.13.1 120 2/14/2025
6.12.5 14 5/3/2026
6.12.4 106 5/9/2025
6.12.1 121 11/17/2024
6.12.0 101 11/19/2024
6.11.2 10 5/3/2026
6.11.1 106 10/6/2024
6.11.0 116 8/15/2024
6.11.0-preview.2 110 6/5/2024
6.10.2 122 8/15/2024
6.10.1 114 6/28/2024
6.10.0 112 6/5/2024
6.9.1 117 2/23/2024
6.8.2 15 5/3/2026
6.8.1 119 2/21/2024
6.8.0 115 11/18/2023
6.7.1 109 2/23/2024
6.7.0 139 8/18/2023
6.6.2 103 2/23/2024
6.6.1 150 7/30/2023
6.6.0 113 5/20/2023
6.6.0-preview.3 118 5/20/2023
6.5.1 105 7/21/2023
6.5.0 116 2/24/2023
6.4.3 103 2/21/2024
6.4.2 144 8/4/2023
6.4.0 131 12/6/2022
6.3.4 119 2/23/2024
6.3.3 124 8/4/2023
6.3.1 119 11/14/2022
6.3.0 131 9/17/2022
6.2.4 133 8/4/2023
6.2.2 117 11/16/2022
6.2.1 119 6/30/2022
6.2.0 137 6/30/2022
6.1.0 125 6/30/2022
6.0.6 118 2/23/2024
6.0.5 119 8/4/2023
6.0.3-rc.1 113 11/25/2022
6.0.2 151 6/30/2022
6.0.0 130 6/30/2022
6.0.0-preview.4.243 123 6/30/2022
6.0.0-preview.3 114 6/30/2022
5.11.7 15 5/3/2026
5.11.6 115 2/23/2024
5.11.5 123 8/1/2023
5.11.3 131 10/13/2022
5.11.2 133 6/30/2022
5.11.0 127 6/30/2022
5.10.0 137 6/30/2022
5.10.0-preview.2.7185 107 6/30/2022
5.9.3 140 11/25/2022
5.9.2 143 6/30/2022
5.9.1 137 6/30/2022
5.9.0 130 6/30/2022
5.9.0-preview.2 118 6/30/2022
5.8.1 130 6/30/2022
5.8.0 142 6/30/2022
5.8.0-preview.3.6823 102 6/30/2022
5.8.0-preview.2.6776 112 6/30/2022
5.8.0-preview.1 159 6/30/2022
5.7.3-rtm.5 120 12/7/2022
5.7.2 140 6/30/2022
5.7.1 113 6/30/2022
5.7.0 118 6/30/2022
5.7.0-rtm.6702 121 6/30/2022
5.7.0-preview.3.6653 131 6/30/2022
5.7.0-preview.2.6618 116 6/30/2022
5.7.0-preview.1.6592 108 6/30/2022
5.6.0 119 6/30/2022
5.6.0-preview.3.6558 129 6/30/2022
5.6.0-preview.2.6489 124 6/30/2022
5.6.0-preview.1.6483 117 6/30/2022
5.5.1 117 6/30/2022
5.5.0 129 6/30/2022
5.5.0-preview.2.6382 128 6/30/2022
5.5.0-preview.1.6319 130 6/30/2022
5.4.0 116 6/30/2022
5.3.1 138 6/30/2022
5.3.0 124 6/30/2022
5.3.0-rtm.6192 119 6/30/2022
5.2.1 126 6/30/2022
5.2.0 139 6/30/2022
5.1.0 146 6/30/2022
5.1.0-preview2.5965 112 6/30/2022
5.0.2 156 6/30/2022
5.0.0 134 6/30/2022
5.0.0-rtm.5867 112 6/30/2022
5.0.0-rtm.5856 114 6/30/2022
5.0.0-preview3.5800 118 6/30/2022
5.0.0-preview2.5782 114 6/30/2022
4.9.7 16 5/3/2026
4.9.6 162 10/13/2022
4.9.5 122 6/30/2022
4.9.4 139 6/30/2022
4.9.3 151 6/30/2022
4.9.2 122 6/30/2022
4.9.2-rtm.5706 121 6/30/2022
4.9.1 121 6/30/2022
4.9.0-rtm.5658 114 6/30/2022
4.8.2 124 6/30/2022
4.8.0 156 6/30/2022
4.8.0-rtm.5362 117 6/30/2022
4.8.0-preview3.5278 129 6/30/2022
4.8.0-preview1.5156 115 6/30/2022
4.7.3 143 6/30/2022
4.7.2 121 6/30/2022
4.7.0 145 6/30/2022
4.7.0-rtm.5148 106 6/30/2022
4.7.0-rtm.5104 118 6/30/2022
4.7.0-preview4.5065 109 6/30/2022
4.7.0-preview1-4986 129 6/30/2022
4.6.4 138 6/30/2022
4.6.3 112 6/30/2022
4.6.2 115 6/30/2022
4.6.1 158 6/30/2022
4.6.0 141 6/30/2022
4.6.0-rtm-4918 105 6/30/2022
4.6.0-rtm-4825 122 6/30/2022
4.6.0-rtm-4791 125 6/30/2022
4.5.3 158 6/30/2022
4.5.2 112 6/30/2022
4.5.0 156 6/30/2022
4.5.0-rtm-4651 109 6/30/2022
4.4.3 120 6/30/2022
4.4.2 122 6/30/2022
4.4.0 122 6/30/2022
4.4.0-preview3-4475 154 6/30/2022
4.3.1 162 6/30/2022
4.3.0 186 6/30/2022
4.3.0-rtm-4324 116 6/30/2022
4.3.0-preview4 120 6/30/2022
4.3.0-preview3-4168 107 6/30/2022
4.3.0-beta1-2418 144 6/30/2022
4.2.0 126 6/30/2022
4.1.0 117 6/30/2022
4.0.0 122 6/30/2022
4.0.0-rtm-2283 112 6/30/2022
4.0.0-rtm-2265 117 6/30/2022
4.0.0-rc3 128 6/30/2022
4.0.0-rc2 142 6/30/2022
4.0.0-rc-2048 113 6/30/2022
3.5.0 129 6/30/2022
3.5.0-rc1-final 106 6/30/2022
3.5.0-beta2-1484 124 6/30/2022
3.5.0-beta-final 129 6/30/2022
3.4.4-rtm-final 120 6/30/2022
3.4.4-rc 125 6/30/2022
3.4.3 126 6/29/2022
3.3.0 134 6/29/2022
3.2.0 126 6/29/2022
1.0.0-pre-20150220044603 132 6/29/2022
1.0.0-pre-20150128082032 110 6/29/2022
1.0.0-pre-20150128071326 109 6/29/2022
1.0.0-pre-20150127085617 132 6/29/2022
1.0.0-pre-20150127072405 102 6/29/2022
1.0.0-pre-20150120213149 133 6/29/2022
1.0.0-pre-20150120004808 108 6/29/2022
1.0.0-pre-20150115030027 140 6/29/2022
1.0.0-pre-20150109221036 147 6/29/2022
1.0.0-pre-20150108074227 118 6/29/2022
1.0.0-pre-20150108073125 127 6/29/2022
1.0.0-pre-20150108010629 113 6/29/2022
1.0.0-master-50072333 122 6/29/2022
1.0.0-master-50060114 115 6/29/2022
1.0.0-master-50050213 119 6/29/2022
1.0.0-master-43652058 116 6/29/2022
1.0.0-master-43642026 128 6/29/2022
1.0.0-master-43522145 108 6/29/2022
1.0.0-master-43500148 115 6/29/2022
1.0.0-master-43450313 123 6/29/2022
1.0.0-master-43440912 115 6/29/2022
1.0.0-master-43422320 112 6/29/2022
1.0.0-master-43421050 141 6/29/2022
1.0.0-master-43421019 111 6/29/2022
1.0.0-master-43402220 125 6/29/2022
1.0.0-master-43362332 119 6/29/2022
1.0.0-master-43362323 114 6/29/2022
1.0.0-master-43250244 127 6/29/2022
1.0.0-master-43250241 132 6/29/2022
1.0.0-master-43250237 118 6/29/2022
1.0.0-master-43250218 137 6/29/2022
1.0.0-juste-43290204 141 6/29/2022