Skip to content

package-url/packageurl-dotnet

Repository files navigation

packageurl-dotnet

Build License NuGet

A .NET parser for Package URLs (ECMA-427). Handles strings like pkg:nuget/Newtonsoft.Json@13.0.1 -- parses them apart, builds them from components, gives you a canonical form back.

Targets .NET Standard 2.0, so it works anywhere from .NET Framework 4.6.1 through .NET 10+.

Install

dotnet add package packageurl-dotnet

Or in your project file:

<PackageReference Include="packageurl-dotnet" Version="1.0.0" />

Usage

Parse a PURL string:

var purl = new PackageUrl("pkg:nuget/Newtonsoft.Json@13.0.1");

Console.WriteLine(purl.Type);      // nuget
Console.WriteLine(purl.Name);      // Newtonsoft.Json
Console.WriteLine(purl.Version);   // 13.0.1

Build one from parts:

var purl = new PackageUrl(
    type: "maven",
    @namespace: "org.apache.commons",
    name: "commons-lang3",
    version: "3.14.0",
    qualifiers: null,
    subpath: null);

Console.WriteLine(purl.ToString());
// pkg:maven/org.apache.commons/commons-lang3@3.14.0

There's also a two-argument shorthand if you only need type and name:

var purl = new PackageUrl("npm", "lodash");

Build from source

Requires .NET SDK 10+.

dotnet pack -c Release
dotnet test -c Release ./tests

Or open PackageUrl.slnx in Visual Studio 2022+ and run tests from Test Explorer.

License

MIT

About

.NET implementation of the package url spec

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages