获取解决方案中使用的所有 NuGet 包的列表 [英] Get a list of all NuGet packages used in a solution
问题描述
我正在寻找一种方法来使用命令行脚本而不是在 Visual Studio 中手动获取解决方案(特别是版本)中每个项目中所有使用过的 NuGet 包的列表.
使用带有命令Get-Package"的包管理器控制台给了我我想要的东西,但它在 VS 之外不可用.
我使用的是本地 NuGet 提要.我的默认包管理格式是 PackageReference.
任何想法都会有所帮助
我确信有更好的方法可以做到这一点,但在使用 PackageReferences 时,这里有一个全面的 PowerShell 方法:
Get-Content .\.sln |where { $_ -match "Project.+, ""(.+)""," } |foreach { $matches[1] } |% {获取内容 $_ |找到<PackageReference Include"} |排序对象 - 唯一
在 .sln 所在的文件夹中运行它.
它产生如下输出:
<块引用> <PackageReference Include="Microsoft.AspNetCore.App"/><PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All"/><PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4"/><PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1"/><PackageReference Include="Microsoft.Extensions.Http" Version="2.1.1"/><PackageReference Include="Microsoft.Extensions.Logging" 版本="2.1.1"/><PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1"/><PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1"/><PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" 版本="2.1.5"/><PackageReference Include="Newtonsoft.Json" Version="11.0.2"/><PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
我故意删除重复项;如果您愿意,可以省略该部分.
在我的例子中,这与 Get-Package
的输出相匹配,只有一个例外是 Microsoft.NETCore.App
,因为它没有在任何地方列为依赖项,但很可能源自
.
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
I'm sure there are better ways to do this, but here's a round-the-houses PowerShell way when using PackageReferences:
Get-Content .\<solution>.sln | where { $_ -match "Project.+, ""(.+)""," } | foreach { $matches[1] } | % {Get-Content $_ | Find "<PackageReference Include" } | Sort-Object -Unique
Run it in the folder where the .sln lives.
It produces output like this:
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.5.0" /> <PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Http" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
I intentionally remove duplicates; you could omit that part if you prefer.
In my case, this matches the output from Get-Package
with the one exception being Microsoft.NETCore.App
, as that is not listed as a dependency anywhere, but is probably rather derived from <TargetFramework>netcoreapp2.1</TargetFramework>
.
这篇关于获取解决方案中使用的所有 NuGet 包的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!