My company has a .NET Powershell module, written in C# to allow advanced users to automate tasks in our product. Currently it targets Powershell 5 using .NET 4.6.1. We would like to allow customers using other operating systems to use it as well, and as it has no OS-specific code, porting it was straightforward.
However, I cannot find documentation on a debugging workflow that should be followed. In standard .NET Powershell, this was quite simple and required a one-time setup procedure:
- Configure the debug executable to be the Powershell path
- Set debug arguments to be a short script that loads the module and if appropriate, executes the function that is being tested.
- Hit F5
However, this doesn't work for Powershell Core. Because the project depends on NuGet packages, the module registration fails with a dependency error. I was able to figure out another workflow but it's a bit more obtuse:
- Navigate to the project directory
- Execute
dotnet publish -f netstandard2.0 -c debug - Execute
Import-Module ./bin/Debug/netstandard2.0/publish/MyModule.dll - Execute
$pidto find the PID - Attach to the PID via Attach to Process in Visual Studio
This works and I have debugged a few issues with this method, but it's not the most pleasant or efficient way to do it. I believe that there must be a better way that is just not well documented.