Recently I created a NuGet package that has a little bit complicated install.ps1
script. The package did not add any references to project, but imported a .targets
file.
The structure of the package is
MyPackage
tools
dir_with_libs
my.targets
content (empty)
libs (empty)
During the installation the relative path to the my.targets
file had to be resolved. This took me some time until I found the proper solution and I had to
- install the package
- see that an error occurred
- uninstall the package
- fix the error
- rebuild the package in another VS.NET window (unfortunately this package was loaded from NuGet feed published on TeamCity, when deploying the package locally to a directory that emulated NuGet feed it is much easier)
- repeat this until there’s no error
In case you don’t want to rebuild the package whenever you have fixed an error in PowerShell script, you have to have solution with 2 or more projects. You will have to install the package to 2 (or more) projects. When you spot the error just fix the install.ps1
file located in the directory where package was created (usually `packages\Package.version\tools\install.ps1′).
Then just reinstall the package in one of yours projects. Because the package is now used in 2 or more projects it is not uninstalled and its directory is not removed. when Uninstall-Package
is invoked. On Install-Package
NuGet finds out that it is already installed in packages
directory and gets the files from there.
Note that this will work only for files in package that are used by NuGet package manager without redeploying, like PowerShell scripts, text files, etc.