DEV Community

Anton Yarkov
Anton Yarkov

Posted on

Tip: Debug your Roslyn Source Generator with JetBrains Rider IDE

.NET Compiler Platform becomes bigger thing, and in the same time, toolset is growing around it. So, it becomes easier to be used.

While writing code that parses/analyzes your code is not a simple task, it might be helpful in various ways. One way I just learned (thanks to my colleagues) is a refactoring.

Usually, code of your source analyzer and/or generator will not be the easiest one to read and maintain. But the idea is it doesn't always need to! The idea is that you have to use source generator as a temporary solution that makes refactoring an easier task for you and your team. And after some refactoring is done, you can simply throw away that code as a legacy one.

I think there is a lot of examples on youtube and in the internet, so I don't need to share another "sample". Instead, I will share most recent practical

Tip of the day

To debug C# Source Generator based on Roslyn .NET Compiler Platform in Rider IDE you need to install Rider 2023 EAP (yes, early preview) and then follow instructions from https://github.com/JoanComasFdz/dotnet-how-to-debug-source-generator-vs2022

Image description

If you haven't use Rider IDE for some reason, you should try it. It much more efficient than Visual Studio, especially at big monolithic projects (you know what I mean, if you work at enterprise). Though, debugging source generators was not possible till recently. From know it all yours!

Top comments (1)

Collapse
 
mpietrowicz profile image
MIP

The instructions in the link are for VS2022, not compatible wit rider EAP.