Created
November 3, 2015 21:07
-
-
Save HellBrick/8d3a6825de12035f3733 to your computer and use it in GitHub Desktop.
Roslyn analyzer test console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.Immutable; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using HellBrick.Diagnostics.UnusedReferences; | |
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.Diagnostics; | |
using Microsoft.CodeAnalysis.MSBuild; | |
namespace TestConsole | |
{ | |
internal class Program | |
{ | |
public static void Main( string[] args ) | |
{ | |
MainAsync( args ).GetAwaiter().GetResult(); | |
} | |
public static async Task MainAsync( string[] args ) | |
{ | |
const string solutionPath = @"F:\Software\AsyncCollections\AsyncCollections.sln"; | |
Solution solution = await MSBuildWorkspace.Create().OpenSolutionAsync( solutionPath ).ConfigureAwait( false ); | |
UnusedReferencesAnalyzer analyzer = new UnusedReferencesAnalyzer(); | |
ImmutableArray<DiagnosticAnalyzer> analyzers = ImmutableArray.Create<DiagnosticAnalyzer>( analyzer ); | |
foreach ( Project project in solution.Projects ) | |
{ | |
Compilation compilation = await project.GetCompilationAsync().ConfigureAwait( false ); | |
CompilationWithAnalyzers compilationWithAnalyzers = compilation.WithAnalyzers( analyzers ); | |
ImmutableArray<Diagnostic> diagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().ConfigureAwait( false ); | |
Console.WriteLine( $"{project.Name}: {diagnostics.Length} diagnostics" ); | |
foreach ( Diagnostic diagnostic in diagnostics ) | |
Console.WriteLine( diagnostic ); | |
Console.WriteLine( "----------------------------------------" ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for putting this together, which nuget package will add Microsoft.CodeAnalysis.MSBuild? I've tried about 10 different rolsyn related ones
Update: not to worry, I was running in .net core which it seems isn't supported