Videos
You have multiple options:
Debugger.LaunchThis 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
For what it's worth, it seems like the best way is unfortunately to pass them in as arguments.
You can do this by clicking on the arrow next to Run button in Visual Studio and selecting 'Project Debug Properties'. From there, you can go to 'Application Arguments' and enter the arguments you want. For example, something like --list all would pass in an array with a length of two where index 0 is --list and index 1 is all.
If someone comes up with a less invasive way, let me know!
Edit: You can also do it from command prompt/powershell by using dotnet run and attaching to the associated process in VS (Debug>Attach to Process)
Unfortunately, this is going to be a very painful experience. There's no real command line debugger available for .NET Core.
However, CoreCLR developers use a plugin for lldb (on *nix) that teaches lldb about a number of commands that it can use to help debug .NET code.
Essentially:
lldb /path/to/dotnet/dotnet
plugin load /path/to/dotnet/shared/Microsoft.NETCore.App/*/libsosplugin.so
b SystemNative_ReceiveMessage
r run
clrstack
Further documentation:
- A tutorial: https://blogs.msdn.microsoft.com/premier_developer/2017/05/02/debugging-net-core-with-sos-everywhere/
- General setup instructions: https://github.com/dotnet/coreclr/blob/master/Documentation/building/debugging-instructions.md
- List of commands: https://github.com/dotnet/coreclr/blob/master/src/ToolBox/SOS/Strike/sosdocsunix.txt
If you start using it, you will quickly realize how painful this is. It's almost worth using VS/Rider/VSCode just for the debugger, sadly.
You can use netcoredbg, a debugger released by Samsung under the MIT license. The tool suports cli (command line), GDB/MI and VSCode Debug Adapterprotocol.
The sample usage are:
$ netcoredbg --interpreter=cli -- dotnet /path/to/program.dll
They released a guide with more information.