diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2020-05-10 14:32:18 +1000 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2020-05-10 14:36:21 +1000 |
commit | 2ab17d9c527629fa70ee4dec81bd0050e1b27f31 (patch) | |
tree | 3f26b86a669052ea980a23f71a158fff9e2cf3a9 /src | |
parent | 477561ad2027979bb9dd3c9ab0a8ff1db9888ecb (diff) | |
download | wix-2ab17d9c527629fa70ee4dec81bd0050e1b27f31.tar.gz wix-2ab17d9c527629fa70ee4dec81bd0050e1b27f31.tar.bz2 wix-2ab17d9c527629fa70ee4dec81bd0050e1b27f31.zip |
Put lock around locating msbuild.
Diffstat (limited to 'src')
-rw-r--r-- | src/WixBuildTools.TestSupport/MsbuildRunner.cs | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/WixBuildTools.TestSupport/MsbuildRunner.cs b/src/WixBuildTools.TestSupport/MsbuildRunner.cs index 97e49d6f..b38387a9 100644 --- a/src/WixBuildTools.TestSupport/MsbuildRunner.cs +++ b/src/WixBuildTools.TestSupport/MsbuildRunner.cs | |||
@@ -15,6 +15,8 @@ namespace WixBuildTools.TestSupport | |||
15 | private static readonly string Msbuild15RelativePath = @"MSBuild\15.0\Bin\MSBuild.exe"; | 15 | private static readonly string Msbuild15RelativePath = @"MSBuild\15.0\Bin\MSBuild.exe"; |
16 | private static readonly string Msbuild16RelativePath = @"MSBuild\Current\Bin\MSBuild.exe"; | 16 | private static readonly string Msbuild16RelativePath = @"MSBuild\Current\Bin\MSBuild.exe"; |
17 | 17 | ||
18 | private static readonly object InitLock = new object(); | ||
19 | |||
18 | private static string Msbuild15Path; | 20 | private static string Msbuild15Path; |
19 | private static string Msbuild16Path; | 21 | private static string Msbuild16Path; |
20 | 22 | ||
@@ -26,40 +28,43 @@ namespace WixBuildTools.TestSupport | |||
26 | 28 | ||
27 | private static MsbuildRunnerResult InitAndExecute(string msbuildVersion, string projectPath, string[] arguments) | 29 | private static MsbuildRunnerResult InitAndExecute(string msbuildVersion, string projectPath, string[] arguments) |
28 | { | 30 | { |
29 | if (Msbuild15Path == null && Msbuild16Path == null) | 31 | lock (InitLock) |
30 | { | 32 | { |
31 | var vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), VswhereRelativePath); | 33 | if (Msbuild15Path == null && Msbuild16Path == null) |
32 | if (!File.Exists(vswherePath)) | ||
33 | { | 34 | { |
34 | throw new InvalidOperationException($"Failed to find vswhere at: {vswherePath}"); | 35 | var vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), VswhereRelativePath); |
35 | } | 36 | if (!File.Exists(vswherePath)) |
37 | { | ||
38 | throw new InvalidOperationException($"Failed to find vswhere at: {vswherePath}"); | ||
39 | } | ||
36 | 40 | ||
37 | var result = RunProcessCaptureOutput(vswherePath, VswhereFindArguments); | 41 | var result = RunProcessCaptureOutput(vswherePath, VswhereFindArguments); |
38 | if (result.ExitCode != 0) | 42 | if (result.ExitCode != 0) |
39 | { | 43 | { |
40 | throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {result.ExitCode}"); | 44 | throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {result.ExitCode}"); |
41 | } | 45 | } |
42 | 46 | ||
43 | Msbuild15Path = String.Empty; | 47 | Msbuild15Path = String.Empty; |
44 | Msbuild16Path = String.Empty; | 48 | Msbuild16Path = String.Empty; |
45 | 49 | ||
46 | foreach (var installPath in result.Output) | 50 | foreach (var installPath in result.Output) |
47 | { | ||
48 | if (String.IsNullOrEmpty(Msbuild16Path)) | ||
49 | { | 51 | { |
50 | var path = Path.Combine(installPath, Msbuild16RelativePath); | 52 | if (String.IsNullOrEmpty(Msbuild16Path)) |
51 | if (File.Exists(path)) | ||
52 | { | 53 | { |
53 | Msbuild16Path = path; | 54 | var path = Path.Combine(installPath, Msbuild16RelativePath); |
55 | if (File.Exists(path)) | ||
56 | { | ||
57 | Msbuild16Path = path; | ||
58 | } | ||
54 | } | 59 | } |
55 | } | ||
56 | 60 | ||
57 | if (String.IsNullOrEmpty(Msbuild15Path)) | 61 | if (String.IsNullOrEmpty(Msbuild15Path)) |
58 | { | ||
59 | var path = Path.Combine(installPath, Msbuild15RelativePath); | ||
60 | if (File.Exists(path)) | ||
61 | { | 62 | { |
62 | Msbuild15Path = path; | 63 | var path = Path.Combine(installPath, Msbuild15RelativePath); |
64 | if (File.Exists(path)) | ||
65 | { | ||
66 | Msbuild15Path = path; | ||
67 | } | ||
63 | } | 68 | } |
64 | } | 69 | } |
65 | } | 70 | } |