vb.net 如何在 Visual Studio 中调试 powershell 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35298963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I debug a powershell module in Visual Studio
提问by DavidM
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. 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.
我正在尝试使用 Visual Studio 2015 将 Powershell 模块编写为 VB.net 项目。我已经能够将一些命令放在一起,将类库编译为 DLL,将模块导入 Powershell 会话并调用我创建的命令。到目前为止一切都很好。但是当我扩展这个模块时,我需要能够调试它。所以我在解决方案中添加了另一个项目,一个控制台应用程序。我将其设置为启动项目,并在第一个项目中引用了 Powershell 类。到目前为止,当我调用 Powershell 函数时,我编写的所有工作都在 EndProcessing() 子例程中完成。我无法从我的控制台应用程序调用它,因为它受到保护。
The question: How do I properly call "get-testcommand" (that I created) 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 and trigger the breakpoints I put in the Powershell class library?
问题:我如何从控制台应用程序正确调用“get-testcommand”(我创建的)powershell 函数,以便 Visual Studio 知道我在单独的项目中引用代码而不是编译的 DLL 并触发断点我把Powershell类库放进去了?
回答by BACON
It's possible to debug your cmdlet directly without needing a separate project. Open the properties of your class library project and configure the Debugtab as follows (assuming Windows is installed to C:):
可以直接调试您的 cmdlet,而无需单独的项目。打开类库项目的属性Debug并按如下方式配置选项卡(假设 Windows 安装到C:):
- Start Action
- Start external program:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- Start external program:
- Start Options
- Command line arguments:
-NoLogo -Command "Import-Module '.\MyModule.dll'; Get-TestCommand;"
- Command line arguments:
- 开始行动
- 启动外部程序:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- 启动外部程序:
- 启动选项
- 命令行参数:
-NoLogo -Command "Import-Module '.\MyModule.dll'; Get-TestCommand;"
- 命令行参数:
回答by Claudius
Edit:try this linkor this step-by-step
Either downdload PowerShell Tools for Visual Studio 2015or use Windows PowerShell ISE.
下载适用于 Visual Studio 2015 的 PowerShell 工具或使用Windows PowerShell ISE。
How to Debug Scripts in Windows PowerShell ISE
Updated: October 17, 2013 Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0, Windows PowerShell 5.0 This topic describes how to debug scripts on a local computer by using the Windows PowerShell? Integrated Scripting Environment (ISE) visual debugging features. How to manage breakpoints How to manage a debugging session How to step over, step into, and step out while debugging How to display the values of variables while debugging
How to manage breakpoints A breakpoint is a designated spot in a script where you would like operation to pause so that you can examine the current state of the variables and the environment in which your script is running. Once your script is paused by a breakpoint, you can run commands in the Console Pane to examine the state of your script. You can output variables or run other commands. You can even modify the value of any variables that are visible to the context of the currently running script. After you have examined what you want to see, you can resume operation of the script. You can set three types of breakpoints in the Windows PowerShell debugging environment: Line breakpoint. The script pauses when the designated line is reached during the operation of the script...
如何在 Windows PowerShell ISE 中调试脚本
更新时间:2013 年 10 月 17 日 适用于:Windows PowerShell 2.0、Windows PowerShell 3.0、Windows PowerShell 4.0、Windows PowerShell 5.0 本主题介绍如何使用 Windows PowerShell 调试本地计算机上的脚本?集成脚本环境 (ISE) 可视化调试功能。如何管理断点 如何管理调试会话 如何在调试时单步执行、单步执行和单步执行 如何在调试时显示变量的值
如何管理断点 断点是脚本中您希望操作暂停的指定位置,以便您可以检查变量的当前状态和脚本运行的环境。一旦脚本被断点暂停,您就可以在控制台窗格中运行命令来检查脚本的状态。您可以输出变量或运行其他命令。您甚至可以修改对当前运行脚本的上下文可见的任何变量的值。检查完要查看的内容后,您可以恢复脚本的操作。您可以在 Windows PowerShell 调试环境中设置三种类型的断点: 行断点。脚本运行过程中到达指定行时脚本暂停...


