NuGet.Protocol 6.9.1

NuGet.Protocol

NuGet.Protocol is a NuGet client SDK library that provides a set of APIs for interacting with NuGet feeds. It provides a way for developers to query NuGet feeds to discover packages and their dependencies, and also to download packages and their associated assets.

Usage

At the center of this library are the PackageSource and SourceRepository types, which represent a NuGet source that may be a file source or an http based source implementing the V2 or V3 protocol.

PackageSource localSource = new PackageSource(@"D:\LocalSource");
SourceRepository localRepository = Repository.Factory.GetCoreV3(localSource);

SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");

The SourceRepository then has a GetResourceAsync method that you can use to acquire implementations of INuGetResource that often are V3 resources.

FindPackageByIdResource resource = await repository.GetResourceAsync<FindPackageByIdResource>(); 

Examples

Search packages

Search for "json" packages using the NuGet V3 Search API:

PackageSearchResource resource = await repository.GetResourceAsync<PackageSearchResource>();
SearchFilter searchFilter = new SearchFilter(includePrerelease: true);

IEnumerable<IPackageSearchMetadata> results = await resource.SearchAsync(
    "json",
    searchFilter,
    skip: 0,
    take: 20,
    NullLogger.Instance,
    CancellationToken.None);

Download a package

Download Newtonsoft.Json v12.0.1 using the NuGet V3 Package Content API:

FindPackageByIdResource resource = await repository.GetResourceAsync<FindPackageByIdResource>();

string packageId = "Newtonsoft.Json";
NuGetVersion packageVersion = new NuGetVersion("12.0.1");
using MemoryStream packageStream = new MemoryStream();

await resource.CopyNupkgToStreamAsync(
    packageId,
    packageVersion,
    packageStream,
    new SourceCacheContext(),
    NullLogger.Instance,
    CancellationToken.None);

Push a package

Push a package using the NuGet V3 Push and Delete API:

PackageUpdateResource resource = await repository.GetResourceAsync<PackageUpdateResource>();

await resource.Push(
    "MyPackage.nupkg",
    symbolSource: null,
    timeoutInSecond: 5 * 60,
    disableBuffering: false,
    getApiKey: packageSource => "my-api-key",
    getSymbolApiKey: packageSource => null,
    noServiceEndpoint: false,
    skipDuplicate: false,
    symbolPackageUpdateResource: null,
    NullLogger.Instance);

Additional documentation

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

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

Packages Downloads
NuGet.DependencyResolver.Core
NuGet's PackageReference dependency resolver implementation.
2

.NET Framework 4.7.2

.NET 5.0

.NET Standard 2.0

Version Downloads Last updated
6.11.0 0 08/13/2024
6.11.0-preview.2 0 06/05/2024
6.10.2 0 08/12/2024
6.10.1 0 06/27/2024
6.10.0 0 05/21/2024
6.9.1 2 07/31/2024
6.8.1 0 02/13/2024
6.8.0 0 11/17/2023
6.7.1 0 02/14/2024
6.7.0 0 08/09/2023
6.6.2 0 02/13/2024
6.6.1 0 06/13/2023
6.6.0 0 05/17/2023
6.6.0-preview.3 0 05/17/2023
6.5.1 0 06/13/2023
6.5.0 0 02/22/2023
6.4.3 0 02/13/2024
6.4.2 0 06/13/2023
6.4.0 0 11/09/2022
6.3.4 0 02/13/2024
6.3.3 0 06/14/2023
6.3.1 0 10/11/2022
6.2.4 0 06/14/2023
6.2.2 0 10/11/2022
6.1.0 0 02/16/2022
6.0.6 0 02/13/2024
6.0.5 0 06/13/2023
6.0.3-rc.1 0 10/11/2022
6.0.2 0 06/14/2022
5.11.6 0 02/13/2024
5.11.5 0 06/15/2023
5.11.3 0 10/11/2022
5.10.0 0 06/15/2021
5.9.3 0 10/11/2022
5.8.1 0 01/16/2021
5.7.3-rtm.5 0 10/11/2022
5.7.2 0 06/14/2022
5.6.0 0 05/20/2020
5.5.1 0 04/03/2020
5.4.0 0 12/03/2019
5.3.1 0 10/25/2019
5.2.1 0 06/14/2022
5.1.0 0 05/21/2019
5.0.2 0 05/14/2019
4.9.6 0 10/11/2022
4.8.2 0 03/12/2019
4.7.3 0 03/15/2019
4.6.4 0 03/15/2019
4.5.3 0 03/15/2019
4.4.3 0 03/15/2019
4.3.1 0 03/12/2019