dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
514 stars 256 forks source link

Debug Roslyn Source Code Generators in VS2022 ? #943

Open ignatandrei opened 2 years ago

ignatandrei commented 2 years ago

For debug Roslyn Source Code Generators in VS2022 , we have had first

Debugger.Launch

and later

<IsRoslynComponent> true</IsRoslynComponent>

But I cannot figure how to do it in VS2022. What will be the profile ?

sharwell commented 2 years ago

I highly recommend debugging source generators by writing unit tests and debugging them from Test Explorer. Debugging a source generator inside of a live Visual Studio instance will be problematic due to their incremental nature and difficulty predicting when they will start.

I don't have a direct answer to debugging inside Visual Studio because for all the source generators I've worked on, I've never tried to debug inside a live instance because the result is always that much worse. The only thing I will do often is open the generated code from underneath the Analyzers node in Solution Explorer to visually inspect it.

dominikjeske commented 2 years ago

I agree with @sharwell - take a look at https://dominikjeske.github.io/source-generators/ in Testing section