In this section, we will write a C# console application based on Roslyn Compiler APIs that loads the given analyzer assembly, executes all diagnostic analyzers defined in this assembly on a given source file, and outputs all the reported analyzer diagnostics.
You will need to have the Visual Studio 2017 Community Edition installed on your machine to execute this recipe. You can install a free Community Edition from https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15.
- Open Visual Studio and create a new C# console application targeting .NET Framework 4.6 or higher, say
ConsoleApp
. - Install the
Microsoft.CodeAnalysis.CSharp
NuGet package (as of this writing, the latest stable version is 2.1.0). For guidance on how to search and install the NuGet package to a project, refer to the recipe Searching and installing...