调试PowerShell cmdlet时出现问题

Sam*_*ell 11 debugging powershell cmdlets visual-studio

我在Windows 7 64位专业版上使用Visual Studio 2010.我在调试自定义PowerShell cmdlet时遇到问题.

组态

  • 语言:C#,面向.NET Framework 3.5 SP1.
  • 平台目标:任何CPU
  • 开始行动: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
  • 命令行参数: -noexit -command Add-PSSnapIn MyCustomSnapIn

问题1:按F5时无法连接(调试→开始调试)

  • PowerShell打开,任务管理器指示powershell.exe作为64位进程运行."映像路径名称"列显示"开始操作"中指定的相同可执行文件.
  • 如果我在Visual Studio中选择Debug→Break All,我会收到一条消息"无法中断执行.此过程当前没有执行您选择调试的代码类型."

问题2:当我按下Ctrl + F5时,意外启动为32位进程(Debug→Start Without Debugging)

  • PowerShell opens. Task Manager indicates that powershell.exe is running as a 32-bit process - this time the Image Path Name shows a SysWOW64 redirection.

The annoying way to debug right now: The only way I've found to debug my cmdlet is to press F5, then select Debug→Detach All, then select Debug→Attach To Process and reattach Visual Studio.

zav*_*vis 6

问题1:

在我看来,这就像VS2010中的一个错误:https: //connect.microsoft.com/VisualStudio/feedback/details/539389/debugging-powershell-cmdlet-from-vs-2010-does-not-stop-at-breakpoints ?WA = wsignin1.0

使用VS2008应该有所帮助.

更新:我找到了更方便的方法来调试PowerShell cmdlet.在解决方案资源管理器中,右键单击解决方案节点 - >添加 - >新建项目 - >选择powershell.exe文件(C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe).将新添加的项目设置为启动项目(右键单击并选择"设置为启动项目").然后转到项目属性(右键单击项目节点并选择"属性")并将"调试器类型"属性设置为"托管(v2.0,v1.1,v1.0)".不要忘记注册您的Provider或CmdLet(通过运行post build事件,请参阅http://msdn.microsoft.com/en-us/library/ms714644%28v=vs.85%29.aspx).现在,程序应该在断点处停止.


x0n*_*x0n 1

问题 1:powershell.exe 实际上不是托管可执行文件。它托管 CLR 本身,因此您需要启用本机代码调试以及托管代码才能正常工作。

至于问题2,我不太确定。显然 VS 本身是一个 32 位进程,所以它可能会干扰这里。