3

Looks like this may have been asked last year but wasn't answered.

I have been writing applications written in PowerShell using VSCode for development. I am starting to write some standard class libraries in C# and found out that I can also do C# development in VSCode using omnisharp.

What I am hoping that I will be able to do is the following:

  • Start debugging in my PowerShell script as I normally would

  • Move the debugger into my C# class so I can troubleshoot issues in my class library

Is this possible? I'm having trouble figuring out where to start. I'm guessing I'll need to do something to build the library in such a way it's able to be debugged and tie it to the PowerShell sessions somehow.

Any help or advice on how to get started would be greatly appreciated.

7
  • 2
    "[...] asked last year but wasn't answered" - got a link? :) Commented Oct 18, 2020 at 16:22
  • Here's the one I was talking about: stackoverflow.com/questions/59445038/… Commented Oct 18, 2020 at 16:47
  • What i have done normally is, write a method outside the powershell cmdlet and test that out within visual studio.. once it's tested successfully, tie it in to the cmdlet. Dont write any code within the cmdlet cs file, but call the method with required variables. Commented Oct 18, 2020 at 17:36
  • I'm afraid you can't transition between debugging sessions in two different debuggers. You'll want to test and debug the classlib and script/module independently Commented Oct 18, 2020 at 19:20
  • 2
    I am assuming that what you need is a DebugBreak() (aka int3) called from your c# class library. For c#, it is called Debugger.Break().. but there is also Debugger.Launch().. see this link. This is how you debug extensions you have written for other applications. In this case, your "extension" is c# and your application is powershell. Commented Oct 18, 2020 at 19:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.