So I'm working on a custom dotnet cli tool as described here. I'm getting started with it and can run my console app using dotnet run, but it's going right past my breakpoints when trying to debug. It does work when running from VS, but I want to be able to play around with passing various arguments and doing that from the application arguments box is not really practical. Any thoughts?
You have multiple options:
Debugger.Launch
This is a function which will pop up a window where you can attach a Visual Studio Debugger. See: Debugger.Launch. This has one theoretical downside (which does not apply to you) it is only usable in Visual Studio and not for example in Rider as the API is not open. (But you when this window pops up you could attach Rider to the process)
"Wait" the first seconds in your program You could just pass an argument to your cli which indicates it should wait x seconds so that you can attach your Debugger.
public static void Main(string[] args)
{
if(args[0] == "waitfordebugger")
{
Thread.Sleep(10000); // Wait 10 Seconds
}
// Do stuff here
You then call your program like this: dotnet run -- waitfordebugger
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With