How can I debug the ISourceGenerator
code during the build process with vscode? Examples on the net use Debugger.Launch()
but this only works in Visual Studio.
[Generator]
public class HelloWorldGenerator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
}
public void Initialize(GeneratorInitializationContext context)
{
if (!Debugger.IsAttached)
{
// how to make it break here?
Debugger.Launch();
}
}
}
If you add such construction:
while (!System.Diagnostics.Debugger.IsAttached)
System.Threading.Thread.Sleep(500);
you will be able to stop build process until you attach any debugger you want. I use Rider IDE, but this should work for VS Code too. When it stucks in cycle, it is available for attaching as .NET Core process:
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