Pankaj Kapare
Pankaj Kapare

Reputation: 7812

How to identify Nuget metapackage?

I am working on tool where I need to programmatically identify Nuget package which is added as PackageReference in my current project is a metapackage or regular package. Since there is not enough documentation around Nuget V3 APIs, finding it hard to get those details. Any pointers in this regard are appreciated.

I tried following code and method GetMetadataAsync returns collection of NuGet.Protocol.PackageSearchMetadata type however there isn't any property on this type which says package is metapackage.

private async void button1_Click(object sender, EventArgs e)
    {
        ILogger log = new Logger();
        List<Lazy<NuGet.Protocol.Core.Types.INuGetResourceProvider>> providers = new List<Lazy<NuGet.Protocol.Core.Types.INuGetResourceProvider>>();
        providers.AddRange(Repository.Provider.GetCoreV3()); 
        PackageSource packageSource = new PackageSource("https://api.nuget.org/v3/index.json");
        SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
        PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
        IEnumerable<IPackageSearchMetadata> searchMetadata = await packageMetadataResource.GetMetadataAsync("Microsoft.AspNetCore.All", true, true,log, CancellationToken.None);
        var list = searchMetadata.ToList();

    }

Upvotes: 0

Views: 200

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100741

A "metapackage" is more a convention for constructing a nuget package than an actual "type" / "property" on a package. If a NuGet package doesn't contain any assets (libraries, content assets, tools, build logic etc.) - practically empty - but only has dependencies on other packages, it is referred to as "metapackage". The only way to test if a package fulfils this definition is to download and inspect its assets.

Upvotes: 1

Related Questions