How to debug powershell module in Visual Studio

I am trying to write a Powershell module as a VB.net project with Visual Studio 2015. I was able to compile several commands, compile the class library into a DLL, import the module into a Powershell session, and call the command I created. All is good so far. But since I am expanding this module, I will need to debug it. Therefore, I added another project to the solution - a console application. I installed it as a startup project and referenced the Powershell class in the first project. While I call the Powershell function, I wrote all the work done in the EndProcessing () routine. I cannot call it from my console application because it is protected.

Question: how to correctly call the get-testcommand function (which was created) from the command line using the console application so that the visual studio knows that I am referencing the code in a separate project and not the compiled DLL and calling breakpoints that I put in a Powershell class library?

+4
source share
2 answers

This allows you to debug your cmdlet directly without a separate project. Open the class library project properties and configure the tab Debugas follows (assuming that Windows is installed on C:):

  • Action start
    • Run an external program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Launch parameters
    • Command line arguments: -NoLogo -Command "Import-Module '.\MyModule.dll'; Get-TestCommand;"

PowerShell Debugging Class Library Project Configuration

Debugging PowerShell Cmdlet

+11
source

: -

downdload PowerShell Visual Studio 2015 Windows PowerShell ISE.

Windows PowerShell ISE

: 17 2013 . : Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0, Windows PowerShell 5.0 , , Windows PowerShell® Integrated Scripting Environment (ISE) . . , ,
script, , , , script . script , , script. . , script. , , ., script. Windows PowerShell: . script , script...

0

Source: https://habr.com/ru/post/1628006/


All Articles