|
6 | 6 | using System.Collections.Immutable;
|
7 | 7 | using System.IO;
|
8 | 8 | using System.Linq;
|
| 9 | +using System.Reflection; |
9 | 10 | using System.Threading;
|
10 | 11 | using System.Threading.Tasks;
|
11 | 12 | using Microsoft.CodeAnalysis.MSBuild;
|
@@ -90,15 +91,31 @@ private static int Main(string[] args)
|
90 | 91 |
|
91 | 92 | Console.CancelKeyPress += delegate { cts.Cancel(); };
|
92 | 93 |
|
93 |
| - RunAsync( |
94 |
| - projectOrSolutionPath, |
95 |
| - ruleTypeBuilder.ToImmutableArray(), |
96 |
| - fileNamesBuilder.ToImmutableArray(), |
97 |
| - configBuilder.ToImmutableArray(), |
98 |
| - copyrightHeader, |
99 |
| - ct).Wait(ct); |
100 |
| - Console.WriteLine("Completed formatting."); |
101 |
| - return 0; |
| 94 | + try |
| 95 | + { |
| 96 | + RunAsync( |
| 97 | + projectOrSolutionPath, |
| 98 | + ruleTypeBuilder.ToImmutableArray(), |
| 99 | + fileNamesBuilder.ToImmutableArray(), |
| 100 | + configBuilder.ToImmutableArray(), |
| 101 | + copyrightHeader, |
| 102 | + ct).Wait(ct); |
| 103 | + Console.WriteLine("Completed formatting."); |
| 104 | + return 0; |
| 105 | + } |
| 106 | + catch (AggregateException ex) |
| 107 | + { |
| 108 | + var typeLoadException = ex.InnerExceptions.FirstOrDefault() as ReflectionTypeLoadException; |
| 109 | + if (typeLoadException == null) |
| 110 | + throw; |
| 111 | + |
| 112 | + Console.WriteLine("ERROR: Type loading error detected. In order to run this tool you need either Visual Studio 2015 or Microsoft Build Tools 2015 tools installed."); |
| 113 | + var messages = typeLoadException.LoaderExceptions.Select(e => e.Message).Distinct(); |
| 114 | + foreach (var message in messages) |
| 115 | + Console.WriteLine("- {0}", message); |
| 116 | + |
| 117 | + return 1; |
| 118 | + } |
102 | 119 | }
|
103 | 120 |
|
104 | 121 | private static async Task RunAsync(
|
|
0 commit comments