NuGet.Packaging 7.3.1

Prefix Reserved
dotnet add package NuGet.Packaging --version 7.3.1
                    
NuGet\Install-Package NuGet.Packaging -Version 7.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NuGet.Packaging" Version="7.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NuGet.Packaging" Version="7.3.1" />
                    
Directory.Packages.props
<PackageReference Include="NuGet.Packaging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NuGet.Packaging --version 7.3.1
                    
#r "nuget: NuGet.Packaging, 7.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NuGet.Packaging@7.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NuGet.Packaging&version=7.3.1
                    
Install as a Cake Addin
#tool nuget:?package=NuGet.Packaging&version=7.3.1
                    
Install as a Cake Tool

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.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (138)

Showing the top 5 NuGet packages that depend on NuGet.Packaging:

Package Downloads
NuGet.Protocol

NuGet's implementation for interacting with feeds. Contains functionality for all feed types.

Microsoft.DotNet.Scaffolding.Shared

Contains interfaces for Project Model and messaging for scaffolding.

NuGet.Packaging.Core

The (former home to) core data structures for NuGet.Packaging. Contains only the type forwarders to the new assembly.

Nuke.Tooling

The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '8aaec258a7e00e5d98e013be025db1a42bc58d79' (see contained AppVeyorSettings.json file for build settings).

Microsoft.CodeAnalysis.Analyzer.Testing

Roslyn Analyzer Test Framework Common Types.

GitHub repositories (70)

Showing the top 20 popular GitHub repositories that depend on NuGet.Packaging:

Repository Stars
DevToys-app/DevToys
A Swiss Army knife for developers.
dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
MonoGame/MonoGame
One framework for creating powerful cross-platform games.
unoplatform/uno
Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
RicoSuter/NSwag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
nissl-lab/npoi
a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
dotnet/msbuild
The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
dotnet/winforms
Windows Forms is a .NET UI framework for building Windows desktop applications.
cake-build/cake
:cake: Cake (C# Make) is a cross platform build automation system.
scriban/scriban
A fast, powerful, safe and lightweight scripting language and engine for .NET
fluentassertions/fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
nuke-build/nuke
🏗 The AKEless Build System for C#/.NET
waf/CSharpRepl
A command line C# REPL with syntax highlighting – explore the language, libraries and nuget packages interactively.
coverlet-coverage/coverlet
Cross platform code coverage for .NET
projectkudu/kudu
Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
dotnet/sdk
Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
open-rpa/openrpa
Free Open Source Enterprise Grade RPA
Pryaxis/TShock
☕️⚡️TShock provides Terraria servers with server-side characters, anti-cheat, and community management tools.
serenity-is/Serenity
Business Apps Made Simple with Asp.Net Core MVC / TypeScript
NuGetPackageExplorer/NuGetPackageExplorer
Create, update and deploy Nuget Packages with a GUI