【问题标题】:Debug C# dll when loaded into powershell's process? Is it even possible?加载到 powershell 进程时调试 C# dll?甚至可能吗?
【发布时间】:2011-11-09 08:53:08
【问题描述】:

我有一个 powershell 脚本,我通过 [Reflection.Assembly]::Load 加载了一个 dll

我想在那个 dll 的源代码中放置刹车点,添加手表等。

附加到powershell进程不起作用(实际上我尝试了powershell ise)。没有其他要附加的进程。有任何想法吗?一旦异常(这是我的异常,所以这应该发生)出现在 VS 中,但我无法重现它。

【问题讨论】:

  • 我当然已经通过附加到 powershell.exe 进程来调试 C# 代码。我不记得曾经在 ISE 上这样做过,但我不知道为什么那也行不通。

标签: c# .net visual-studio debugging powershell


【解决方案1】:

作为替代方案,您可以在库中创建一个帮助类:

namespace Something {
    public static class DebugHelper {
        public static void AttachDebugger() {
            System.Diagnostics.Debugger.Launch();
        }
    }
}

然后,您可以从 PowerShell 调用该方法,您将获得附加的调试器。

【讨论】:

  • 我注意到有时它不起作用。 VS 启动,但未捕获异常。请注意,我直接从 power shell 使用了这一行:[System.Diagnostics.Debugger]::Launch()
  • 我的想法是使用 [Something.DebugHelper]::AttachDebugger(),所以你的代码中有调试器,然后很容易添加断点等,但可能你的解决方案更简单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多