Wednesday, December 3, 2014

New Video: Building a Diagnostic Analyzer with Code Fix in Visual Studio 2015

Code analyzers are pretty cool. Many of us have been using ReSharper or another third-party tool with Visual Studio for many years. With the latest preview of Visual Studio 2015 and the .NET Compiler Platform ("Roslyn"), it's really easy to build these code analyzers for yourself.

You can spend about 45 minutes following along with me in my latest video:

Building a Diagnostic Analyzer with Code Fix in Visual Studio 2015
The .NET Compiler Platform ("Roslyn") allows us to easily create diagnostic analyzers that can alert us to issues in code as well as provide automated code fixes. We'll create a very simple analyzer and fix to show how easy this is to do. This uses the Visual Studio 2015 Preview, and instructions on getting what you need are in the video.
Here's a sample that I built:

This analyzer looks for "if" statements that don't have curly braces, warns us about it, and then offers to add the braces for us automatically.

You can get the code from my website:

New to Roslyn
Now, I am very new to Roslyn (now called the ".NET Compiler Platform"). Many people I know have been working with it for years, but I've been struggling with whether it is relevant to me. I still don't have the answer to that question.

But at the MVP Summit last month, there was a hackathon where we built diagnostic analyzers and code fixes. This was a whirlwind introduction to Roslyn, the syntax visualizer, and the diagnostic analyzer project template. After going through the demo, I slowed down to try to understand things a bit better.

Today, I released a video that shows my initial exploration. I write a simple code analyzer and walk through the process of building it. You can watch the video on YouTube: Building a Diagnostic Analyzer with Code Fix in Visual Studio 2015.

I'm definitely not an expert (just a month in to actually using it). But I thought it would be useful to share my experiences.

If nothing else, this has given me a good appreciation for what benefits we get with the .NET Compiler Platform so I can think about possible uses in the future.

Happy Coding!

No comments:

Post a Comment