Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 68004f5

Browse files
committed
Merge pull request #51 from dotnet/terrajobst/detect-missing-dev14
Add error handling do detect when MSBuild 14 is missing
2 parents 788eabc + ab60dbb commit 68004f5

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/CodeFormatter/Program.cs

+26-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Immutable;
77
using System.IO;
88
using System.Linq;
9+
using System.Reflection;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Microsoft.CodeAnalysis.MSBuild;
@@ -90,15 +91,31 @@ private static int Main(string[] args)
9091

9192
Console.CancelKeyPress += delegate { cts.Cancel(); };
9293

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+
}
102119
}
103120

104121
private static async Task RunAsync(

0 commit comments

Comments
 (0)