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+.
dotnet add package packageurl-dotnetOr in your project file:
<PackageReference Include="packageurl-dotnet" Version="1.0.0" />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.1Build 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.0There's also a two-argument shorthand if you only need type and name:
var purl = new PackageUrl("npm", "lodash");Requires .NET SDK 10+.
dotnet pack -c Release
dotnet test -c Release ./testsOr open PackageUrl.slnx in Visual Studio 2022+ and run tests from Test Explorer.