Is there any accessible API via an MSBuild task, target or otherwise that allows me to query what version of a NuGet package a given PackageReference will resolve (or has already resolved) to?
For example, if I have a csproj with
<PackageReference Include=“MyPkg” Version=“1.*”/>
And I have a custom target where I want to
<MyTarget>
<GetVersionOfResolvedPackageReference Name=“MyPkg” OutputProperty=“IWantToKnowThis” /> <!— or something —>
...
From How NuGet resolves package dependencies:
This
PowerShell
script recursively parses directories to findproject.assets.json
and writes result inPackageReference.ini
file. You can call script from MSBuild via Exec task and after that read file via ReadLinesFromFile and performing further processing.