如何调试 NuGet 包的 install.ps1 脚本

How to debug install.ps1 script of NuGet package(如何调试 NuGet 包的 install.ps1 脚本)

本文介绍了如何调试 NuGet 包的 install.ps1 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此我们可以在 NuGet 包中包含安装/卸载 powershell 脚本.我试过了,但我的 install.ps1 不起作用.有没有可能找出原因?调试、记录,什么?

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?

更新

请注意,该脚本是作为 Nuget 包安装过程的一部分执行的.它可能是非常特定于 Nuget 的.

Please note that the script is executed as part of an installation process of Nuget package. It may be very Nuget-specific.

推荐答案

也许我迟到了,但这里有一个调试 NuGet 特定脚本的解决方案,NuGet 包 NuGetDebugTools.它的脚本 Add-Debugger.ps1 为 NuGet 包添加了一个简单而有效的调试器管理控制台.

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.

示例场景:

  • 启动 Visual Studio
  • 打开 NuGet 控制台并输入命令

  • start Visual Studio
  • open NuGet console and type commands

PM> Add-Debugger [-ReadHost]
PM> Set-PSBreakpoint -Command init
PM> Set-PSBreakpoint -Command install

(或者设置更具体的断点,见help Set-PSBreakpoint)

(or set more specific breakpoints, see help Set-PSBreakpoint)

  • 打开 Visual Studio 解决方案或为已打开的调用 Install-Package XYZ
  • 调试器输入对话框出现在任何 init.ps1install.ps1 调用
  • 类型?作为调试器输入,看看你能做什么:

  • open a Visual Studio solution or invoke Install-Package XYZ for already opened
  • the debugger input dialog appears on any init.ps1 and install.ps1 invoked
  • type ? as debugger input and see what you can do:

s, StepInto  Step to the next statement into functions, scripts, etc.
v, StepOver  Step to the next statement over functions, scripts, etc.
o, StepOut   Step out of the current function, script, etc.
c, Continue  Continue operation (also on empty input).
q, Quit      Stop operation and exit the debugger.
?, h         Display this help message.
r            Display PowerShell command history.
k            Display call stack (Get-PSCallStack).
<number>     Show debug location in context of <number> lines.
+<number>    Set location context preference to <number> lines.
<command>    Invoke any PowerShell <command> and write its output.

  • 键入其他调试器和 PowerShell 命令并在 NuGet 控制台中观察输出

  • type other debugger and PowerShell commands and watch the output in the NuGet console

    v1.4.0 - 新开关 ReadHost 告诉使用 Read-Host 进行输入,而不是默认的 GUI 输入框.

    v1.4.0 - New switch ReadHost tells to use Read-Host for input instead of the default GUI input box.

    这篇关于如何调试 NuGet 包的 install.ps1 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

  • 本文标题为:如何调试 NuGet 包的 install.ps1 脚本

    基础教程推荐