调试 - 进入通过 API 执行的 PowerShell 脚本

Debugging - Step into PowerShell Script Executed via API

我正在使用 System.Management.Automation.PowerShell 从 C# 应用程序以编程方式执行 PowerShell 脚本。 PowerShell 脚本加载一个用于执行其活动的 .Net dll。

var script = "Add-Type -Path 'MyLibrary.dll'; ....";

using (var powershell = PowerShell.Create()) {
    powershell.AddScript(script);

    powershell.Invoke();
}

是否有可能以某种方式将 Visual Studio 的调试器连接到 PowerShell 对象实例,以便调试器可以无缝地从 C# 应用程序进入 PowerShell 脚本,并从该脚本进入 MyLibrary.dll(假设我有 dll 的符号)?

Edit:根据以下内容,似乎没有办法将 Visual Studio 中的调试从 C# 无缝流到 PowerShell。但是,可以使用 VS 调试启动的和由 PowerShell 启动的 C# 代码。

您可以通过在助手中调用以下命令来调试 dll 文件 class:

System.Diagnostics.Debugger.Launch();