roslyn-sdk icon indicating copy to clipboard operation
roslyn-sdk copied to clipboard

Debug Roslyn Source Code Generators in VS2022 ?

Open ignatandrei opened this issue 3 years ago • 2 comments

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 ?

ignatandrei avatar Jan 01 '22 17:01 ignatandrei

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.

sharwell avatar Feb 02 '22 16:02 sharwell

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

dominikjeske avatar Feb 12 '22 17:02 dominikjeske