Fix an error in PowerShell script in NuGet package without redeployment

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

  1. install the package
  2. see that an error occurred
  3. uninstall the package
  4. fix the error
  5. 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)
  6. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Blue Captcha Image
Refresh

*