1

Inside a nuget init.ps1 https://docs.nuget.org/create/creating-and-publishing-a-package#automatically-running-powershell-scripts-during-package-installation-and-removal how do i get access to the current running version of nuget so as to do some switching logic on it?

Note I am running inside the Visual Studio context

Simon
  • 33,714
  • 21
  • 133
  • 202
  • possible duplicate of [Use NuGet powershell commandlets from outside Visual Studio](http://stackoverflow.com/questions/12884282/use-nuget-powershell-commandlets-from-outside-visual-studio) – juanvan Aug 20 '15 at 04:32
  • @juanvan how is that other question the same as this one? i am not running outside of VS – Simon Aug 20 '15 at 04:35
  • It is in the Help of VS, running dir *.exe | %{ $_.VersionInfo } gave me a version of 1.0.0.0 and that is not right on the nuget.exe found. – juanvan Aug 20 '15 at 04:48

2 Answers2

0

Get-WmiObject -Class Win32_Product | Where-Object {$_.name -like "nuget"} You will need to know the version of VS too, having 12 and 13 has 2 versions of VS.

juanvan
  • 671
  • 7
  • 19
0

You can get the NuGet assembly file version and the product version in init.ps1 using the following:

// Returns the file version (e.g. 2.8.60723.765) as a string
$package.GetType().Assembly.GetName().Version.ToString()

// Returns the product version (e.g. 2.8.7) as a string
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($package.GetType().Assembly.Location).ProductVersion
Matt Ward
  • 47,057
  • 5
  • 93
  • 94