Question

I'm authoring a NuGet package that needs to, on install time, edit an existing file in the project and put the package's version number into that file. I can do the file edits from install.ps1 just fine, but I can't figure out how to get the package version.

The install.ps1 file gets four parameters, one of which is $package. The sum total of documentation on this parameter is:

$package is a reference to the package object. 

I'm assuming the version is in this thing somewhere, but I can find no documentation on what this parameter is, what the type is, what the properties are, anything.

I tried using the NuGetPSVariables test package, it just printed out the package name and version as a string, but it wasn't the right format.

Does anyone have a reliable way to get the package version from inside the install.ps1 file that doesn't involve string hacking on the $installPath?

Was it helpful?

Solution

The $package parameter passed to your install.ps1 script will implement the IPackage interface. This interface derives from the IPackageName interface which has a Version property which you can use to get the package version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top