Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

c# - Get a list of all NuGet packages used in a solution

I'm looking for a way to get a list of all used NuGet packages in every project in a solution (and specifically the version) using command-line script and not manually in Visual Studio.

Using the Package Manager Console with the command "Get-Package" gives me what I want, but it is unavailable outside of VS.

I'm using is a local NuGet feed. My default package management format is PackageReference.

Any idea would be helpful

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

PackageReference as a package management format only works on a per project basis. So you would need to "analyze" each project individually.

From the commandline, there "will" be a way to list all the packages. It's the "dotnet list package" command. I say will, because it's still in preview. You can download the 2.2.100 version from here. Related spec.

The simplest usage example is:

dotnet list YourSln.sln package

If you do not want to use a dotnet.exe preview, you can consider writing your own tool, by reading the assets files for each project, which is what the actual command does. For reference, see code here and here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...