@@ -77,7 +77,7 @@ private static async Task MainAsync(string[] args, CancellationToken cancellatio
7777
7878 MSBuildWorkspace workspace = MSBuildWorkspace . Create ( ) ;
7979 string solutionPath = args . SingleOrDefault ( i => ! i . StartsWith ( "/" , StringComparison . Ordinal ) ) ;
80- Solution solution = workspace . OpenSolutionAsync ( solutionPath , cancellationToken ) . Result ;
80+ Solution solution = await workspace . OpenSolutionAsync ( solutionPath , cancellationToken ) . ConfigureAwait ( false ) ;
8181
8282 Console . WriteLine ( $ "Loaded solution in { stopwatch . ElapsedMilliseconds } ms") ;
8383
@@ -373,13 +373,29 @@ private static async Task<ImmutableDictionary<ProjectId, ImmutableArray<Diagnost
373373 /// <returns>A list of diagnostics inside the project</returns>
374374 private static async Task < ImmutableArray < Diagnostic > > GetProjectAnalyzerDiagnosticsAsync ( ImmutableArray < DiagnosticAnalyzer > analyzers , Project project , CancellationToken cancellationToken )
375375 {
376- Compilation compilation = await project . GetCompilationAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
376+ var supportedDiagnosticsSpecificOptions = new Dictionary < string , ReportDiagnostic > ( ) ;
377+ foreach ( var analyzer in analyzers )
378+ {
379+ foreach ( var diagnostic in analyzer . SupportedDiagnostics )
380+ {
381+ // make sure the analyzers we are testing are enabled
382+ supportedDiagnosticsSpecificOptions [ diagnostic . Id ] = ReportDiagnostic . Default ;
383+ }
384+ }
385+
386+ // Report exceptions during the analysis process as errors
387+ supportedDiagnosticsSpecificOptions . Add ( "AD0001" , ReportDiagnostic . Error ) ;
388+
389+ // update the project compilation options
390+ var modifiedSpecificDiagnosticOptions = supportedDiagnosticsSpecificOptions . ToImmutableDictionary ( ) . SetItems ( project . CompilationOptions . SpecificDiagnosticOptions ) ;
391+ var modifiedCompilationOptions = project . CompilationOptions . WithSpecificDiagnosticOptions ( modifiedSpecificDiagnosticOptions ) ;
392+ var processedProject = project . WithCompilationOptions ( modifiedCompilationOptions ) ;
393+
394+ Compilation compilation = await processedProject . GetCompilationAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
377395 CompilationWithAnalyzers compilationWithAnalyzers = compilation . WithAnalyzers ( analyzers , cancellationToken : cancellationToken ) ;
378396
379397 var allDiagnostics = await compilationWithAnalyzers . GetAllDiagnosticsAsync ( ) . ConfigureAwait ( false ) ;
380-
381- // We want analyzer diagnostics and analyzer exceptions
382- return allDiagnostics . RemoveRange ( compilation . GetDiagnostics ( ) ) ;
398+ return allDiagnostics ;
383399 }
384400
385401 private static void PrintHelp ( )
0 commit comments