Get Nuget Package version from query
Hi,
Is there a good way of reporting the package version used in a query? I'm targeting a pre-release package and want to add a dump of the package version to remind me, however, I'm not clear on the best way of getting to the global package info from the PackageID reference.
So far I've looked at theses options:
void Main()
{
Util.CurrentQuery.NuGetReferences.Dump("Get Nuget package refs"); //the NuGet refs only
var t = typeof(Microsoft.Identity.Client.ClientApplicationBase);
t.Assembly.GetName().Version.ToString().Dump("Assembly version"); //the assembly version
Util.CurrentQuery.GetRawHeader().Dump("GetRawHeader"); //the xml
}
Ideally, I'd also like to do the reverse as well - iterate through all NuGet packages and report on which queries they're being used in.
Best regards
John
Is there a good way of reporting the package version used in a query? I'm targeting a pre-release package and want to add a dump of the package version to remind me, however, I'm not clear on the best way of getting to the global package info from the PackageID reference.
So far I've looked at theses options:
void Main()
{
Util.CurrentQuery.NuGetReferences.Dump("Get Nuget package refs"); //the NuGet refs only
var t = typeof(Microsoft.Identity.Client.ClientApplicationBase);
t.Assembly.GetName().Version.ToString().Dump("Assembly version"); //the assembly version
Util.CurrentQuery.GetRawHeader().Dump("GetRawHeader"); //the xml
}
Ideally, I'd also like to do the reverse as well - iterate through all NuGet packages and report on which queries they're being used in.
Best regards
John
Comments
Try this: You'll notice the NuGet package version inside the path. You could either parse this with regex, or more reliably, walk the directory structure up until you find a file called LINQPadPackageInfo.xml. If you look in that file, you'll find the currently downloaded version number.
However, more recent runs (having added a couple of extra packages for testing) has assemblyPath returning something in the temp directory and so, of course, looking for the folder by name doesn't work:
"C:\Users\John\AppData\Local\Temp\LINQPad5\_soklyzql\shadow_csksxj\microsoft.identity.client.dll"
I guess an alternative is to go top down, so this works: Might Util.GetLocalNugetDirectory() be a candidate for a more reliable way of getting the local packages path?
In any case, thanks very much for your help.
Best regards
John
For anyone else who stumbles across this here's an extension method: ...which can then be used either for the CurrentQuery or for all queries: