So we can include an install/uninstall powershell scripts in a NuGet package. I tried, but my install.ps1 does not work. Is there any possibility to find out why? Debugging, logging, anything?
Update
Please note that the script is executed as part of an installation process of Nuget package. It may be very Nuget-specific.
This is how I was able to step-through install.ps1 using PowerShell ISE:
To be able to step through execution of the install script using PowerShell ISE follow these steps: Enable execution of assemblies built with .Net 4
Either
C:\Windows\System32\WindowsPowerShell\v1.0 Or
C:\Windows\SysWOW64\WindowsPowerShell\v1.0
Depending on which version of PS you're using If files are not there create them
Either C:\Windows\System32\WindowsPowerShell\v1.0 Or C:\Windows\SysWOW64\WindowsPowerShell\v1.0
Depending on which version of PS you're using
If config files are not there create them
powershell.exe.config:
powershell_ise.exe.config:
To be able to run PowerShell scripts included with a NuGet package the execution policy will need to be changed:
Set-ExecutionPolicy RemoteSigned -Scope Process
Copy install.ps1 that you want to debug and modify it's contents as follows:
delete the parameters block
import a module which allows to use nuget cmdlets outside of the VS host process
Download http://community.sharpdevelop.net/blogs/mattward/NuGet/NuGetOutsideVisualStudio.zip Extract contents of the bin folder to some place and then import the PackageManagement.Cmdlets.dll
like so:
now you are able to set all the parameters manually like so:
That still leaves $package object unset but I found that script doesn't really refer to that parameter
References: http://community.sharpdevelop.net/blogs/mattward/archive/2011/06/12/InstallingNuGetPackagesOutsideVisualStudio.aspx
Run your scripts through the Package Manager Console in VS (details on the console at https://docs.nuget.org/ndocs/tools/package-manager-console) -- and anything that causes an error along the way will be written out in red.
Also, you can write diagnostic trace type info with Write-Host to the same console.
Use
Set-PsDebug -trace 2
to see what is happening.Perhaps I am late to the party but here is a solution for debugging NuGet specific scripts, the NuGet package NuGetDebugTools. Its script Add-Debugger.ps1 adds a simple and yet effective debugger to the NuGet package manager console.
The sample scenario:
open NuGet console and type commands
(or set more specific breakpoints, see
help Set-PSBreakpoint
)type ? as debugger input and see what you can do:
type other debugger and PowerShell commands and watch the output in the NuGet console
v1.4.0 - New switch
ReadHost
tells to useRead-Host
for input instead of the default GUI input box.You might call
Start-Transcript
at the beginning of install script andStop-Transcript
at the end. You would probably wrap the install code like this:Also
$ErrorActionPreference = 'inquire'
(instead of stop) could possibly work. However, no chance to try it now. See http://tasteofpowershell.blogspot.com/2008/07/handling-errors-in-powershell.html