|
1 | 1 | using System.Diagnostics;
|
2 | 2 | using Google.Protobuf;
|
3 | 3 | using Microsoft.CodeAnalysis.Elfie.Extensions;
|
| 4 | +using Microsoft.CodeAnalysis.MSBuild; |
4 | 5 | using Microsoft.Extensions.DependencyInjection;
|
5 | 6 | using Microsoft.Extensions.FileSystemGlobbing;
|
6 | 7 | using Microsoft.Extensions.Hosting;
|
@@ -49,6 +50,33 @@ public static async Task<int> Process(
|
49 | 50 | nugetConfigPath
|
50 | 51 | );
|
51 | 52 | await ScipIndex(host, options);
|
| 53 | + |
| 54 | + |
| 55 | + // Log msbuild workspace diagnostic information after the index command finishes |
| 56 | + // We log the MSBuild failures as error since they are often blocking issues |
| 57 | + // preventing indexing. However, we log msbuild warnings as debug since they |
| 58 | + // do not block indexing usually and are much noisier |
| 59 | + var workspaceLogger = host.Services.GetRequiredService<ILogger<MSBuildWorkspace>>(); |
| 60 | + var workspaceService = host.Services.GetRequiredService<MSBuildWorkspace>(); |
| 61 | + if (workspaceService.Diagnostics.Any()) |
| 62 | + { |
| 63 | + var diagnosticGroups = workspaceService.Diagnostics |
| 64 | + .GroupBy(d => new { d.Kind, d.Message }) |
| 65 | + .Select(g => new { g.Key.Kind, g.Key.Message, Count = g.Count() }); |
| 66 | + foreach (var diagnostic in diagnosticGroups) |
| 67 | + { |
| 68 | + var message = $"{diagnostic.Kind}: {diagnostic.Message} (occurred {diagnostic.Count} times)"; |
| 69 | + if (diagnostic.Kind == Microsoft.CodeAnalysis.WorkspaceDiagnosticKind.Failure) |
| 70 | + { |
| 71 | + workspaceLogger.LogError(message); |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + workspaceLogger.LogDebug(message); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
52 | 80 | return 0;
|
53 | 81 | }
|
54 | 82 |
|
|
0 commit comments