In this recipe, we wrote a C# console application based on the Roslyn Compiler API to load and execute diagnostic analyzers from an analyzer assembly and report the diagnostics reported by the analyzers. These operations are very similar to what the C# compiler would do when you compile source files with /analyzer:<%analyzer_file_path%> command line switch. Let's walk through the code and understand how we implemented these operations:
public static void Main(string[] args){ // Parse arguments to get analyzer assembly file and source file. var files = ParseArguments(args); if (files.analyzerFile == null || files.sourceFile == null) { return; } // Parse source file and create a compilation. var compilation = CreateCompilation(files.sourceFile); ...