|
| 1 | +## About this project |
| 2 | + |
| 3 | +The Chocolatey.PowerShell project within the Chocolatey CLI solution is the compiled PowerShell cmdlets. |
| 4 | + |
| 5 | +## Debugging the Chocolatey.PowerShell cmdlets |
| 6 | + |
| 7 | +Because the Chocolatey.PowerShell module is a compiled module, debugging it is a little more involved than a script based module. |
| 8 | +If you need to debug cmdlets within a Chocolatey CLI execution, you can merely create a package that calls the Chocolatey.PowerShell function you are debugging, and it will work. |
| 9 | +However, if you need to test the functions outside of a Chocolatey CLI invocation, that is a little bit more involved. |
| 10 | +Fortunately, Marc-Andr� Moreau provides and [excellent guide](https://awakecoding.com/posts/debugging-powershell-binary-modules-in-visual-studio/) on debugging a binary PowerShell module from Visual Studio. |
| 11 | +The below steps are greatly simplified and targetted specifically at the Chocolatey.PowerShell project. |
| 12 | + |
| 13 | +1. Edit or create a `Chocolatey.PowerShell.csproj.user` file beside the `Chocolatey.PowerShell.csproj` file (located at `$ChocoSourceRepository/src/Chocolatey.PowerShell`). |
| 14 | +1. Set it's contents to the XML following this list. |
| 15 | +1. (Re)Launch Visual Studio to have it pick up the addition of the `Chocolatey.PowerShell.csproj.user` file. |
| 16 | +1. Set the `Chocolatey.PowerShell` project as the startup project. |
| 17 | +1. Start the debugger. |
| 18 | +1. In the Windows PowerShell that launched, import the module with `Import-Module ./Chocolatey.PowerShell.dll`. |
| 19 | +1. Now when you call any of the compiled PowerShell files, you will be able to stop at set breakpoints and debug as normal. |
| 20 | + |
| 21 | +```xml |
| 22 | +<?xml version="1.0" encoding="utf-8"?> |
| 23 | +<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 24 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> |
| 25 | + <StartAction>Program</StartAction> |
| 26 | + <StartProgram>c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram> |
| 27 | + </PropertyGroup> |
| 28 | +</Project> |
| 29 | +``` |
0 commit comments