How to list all installed NuGet Packages and Versions using .NET CLI

2.9k views Asked by At

How to list all locally installed NuGet packages using .NET Core CLI in a ASP.NET Core project without Visual Studio 2017?

I have a ASP.NET Core 2.1 project. I have a <PackageReference Include="Microsoft.AspNetCore.App" /> by default that don't have a Version in it. I'd like to know what's the Version it used. I can't find any CLI command to query that information.

1

There are 1 answers

1
Radim Göth On

If Version attribute for metapackage (which Microsoft.AspNetCore.Appis) is not supplied, the lowest locally installed version is taken. You can check which versions you have installed locally in %userprofile%\.nuget\packages\microsoft.aspnetcore.app

However, you usually don't want to know metapackage version, but a version of each package in it and you can determine them by:

var referencedAssemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
foreach (var assembly in referencedAssemblies)
   Console.WriteLine($"{assembly.Name} {assembly.Version}");