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>
.