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

标签 c# visual-studio powershell nuget

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

更新

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

最佳答案

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

更新:脚本现在位于 PSGallery Add-Debugger . NuGetDebugTools 包不再更新。要么使用 PowerShelf或从存储库中获取单独的脚本。

示例场景:

  • 启动 Visual Studio

  • 打开 NuGet 控制台并输入命令

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

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

  • 打开 Visual Studio 解决方案或调用已打开的 Install-Package XYZ

  • 调试器输入对话框出现在任何调用的 init.ps1install.ps1

  • 输入 ?作为调试器输入,看看你能做什么:

      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 控制台中观察输出


v1.4.0 - 新开关 ReadHost 指示使用 Read-Host 代替默认的 GUI 输入框进行输入。

关于c# - 如何调试NuGet包的install.ps1脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7031944/

相关文章:

c# - 如何创建与 Microsoft.Azure.Management.Compute 一起使用的 ServiceClientCredential

c# - 添加/p :Platform ="Any CPU" parameter forces the build in Debug configuration

c++ - 拖放文件名 Visual (Managed) C++

powershell - 将成员/列附加到 PSObject

powershell - 为什么我的 DNS MX 查询返回 SOA 记录?

c# - 在 WP7 中手动退出文本框的键入模式

c# - 获取事件窗口文本(并向其发送更多文本)

c++ - 有没有办法在 VS 调试器中自定义自定义对象的工具提示?

visual-studio - 交替使用 msbuild 和 devenv 构建相同的解决方案

powershell - 使用 Session 和 CredSSP 的 PSRemoting 错误