如何在Visual Studio中调试Windows PowerShell模块? [英] How do I debug a Windows PowerShell module in Visual Studio?

查看:75
本文介绍了如何在Visual Studio中调试Windows PowerShell模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio 2015作为VB.NET项目编写PowerShell模块.我已经能够将一些命令放在一起,将类库编译到DLL中,然后将模块导入PowerShell会话中并调用我创建的命令.到目前为止一切都很好.但是当我扩展此模块时,我将需要能够对其进行调试.

I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it.

因此,我在解决方案中添加了另一个项目,一个控制台应用程序.我将其设置为启动项目,并在第一个项目中引用了PowerShell类.到目前为止,当我调用PowerShell函数时,我已在 EndProcessing()子例程中完成了所有工作.我无法从我的控制台应用程序中调用它,因为它受到了保护.

So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So far when I call the PowerShell function I wrote all the work is being done in the EndProcessing() subroutine. I can't call that from my console app because It's protected.

问题:如何从控制台应用程序正确调用我的 Get-TestCommand PowerShell函数,以使Visual Studio知道我在单独的项目中引用代码,而不是在已编译的DLL中引用代码在触发我放入Powershell类库中的断点时?

The question: How do I properly call my Get-TestCommand PowerShell function from a console app in such a way that Visual Studio knows I'm referencing code in a separate project and not the compiled DLL while triggering the breakpoints I put in the Powershell class library?

推荐答案

可以直接调试cmdlet,而无需单独的项目.打开类库项目的属性,并按如下所示配置 Debug 选项卡(假设Windows安装到 C:):

It's possible to debug your cmdlet directly without needing a separate project. Open the properties of your class library project and configure the Debug tab as follows (assuming Windows is installed to C:):

  • 开始行动
    • 启动外部程序: C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe
    • 命令行参数: -NoLogo -Command导入模块'.\ MyModule.dll'; Get-TestCommand;"

    这篇关于如何在Visual Studio中调试Windows PowerShell模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆