Put lock around locating msbuild.
Sean Hall committed
May 10, 2020 at 14:32 UTC
2ab17d9c527629fa70ee4dec81bd0050e1b27f31
1 file changed
+29
-24
src/WixBuildTools.TestSupport/MsbuildRunner.cs
+29
-24
@@ -15,6 +15,8 @@ namespace WixBuildTools.TestSupport
15
private static readonly string Msbuild15RelativePath = @"MSBuild\15.0\Bin\MSBuild.exe";
16
private static readonly string Msbuild16RelativePath = @"MSBuild\Current\Bin\MSBuild.exe";
17
18
+ private static readonly object InitLock = new object();
19
+
20
private static string Msbuild15Path;
21
private static string Msbuild16Path;
22
@@ -26,40 +28,43 @@ namespace WixBuildTools.TestSupport
28
29
private static MsbuildRunnerResult InitAndExecute(string msbuildVersion, string projectPath, string[] arguments)
30
{
29
- if (Msbuild15Path == null && Msbuild16Path == null)
31
+ lock (InitLock)
32
{
31
- var vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), VswhereRelativePath);
32
- if (!File.Exists(vswherePath))
33
+ if (Msbuild15Path == null && Msbuild16Path == null)
34
{
34
- throw new InvalidOperationException($"Failed to find vswhere at: {vswherePath}");
35
- }
35
+ var vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), VswhereRelativePath);
36
+ if (!File.Exists(vswherePath))
37
+ {
38
+ throw new InvalidOperationException($"Failed to find vswhere at: {vswherePath}");
39
+ }
40
37
- var result = RunProcessCaptureOutput(vswherePath, VswhereFindArguments);
38
- if (result.ExitCode != 0)
39
- {
40
- throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {result.ExitCode}");
41
- }
41
+ var result = RunProcessCaptureOutput(vswherePath, VswhereFindArguments);
42
+ if (result.ExitCode != 0)
43
+ {
44
+ throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {result.ExitCode}");
45
+ }
46
43
- Msbuild15Path = String.Empty;
44
- Msbuild16Path = String.Empty;
47
+ Msbuild15Path = String.Empty;
48
+ Msbuild16Path = String.Empty;
49
46
- foreach (var installPath in result.Output)
47
- {
48
- if (String.IsNullOrEmpty(Msbuild16Path))
50
+ foreach (var installPath in result.Output)
51
{
50
- var path = Path.Combine(installPath, Msbuild16RelativePath);
51
- if (File.Exists(path))
52
+ if (String.IsNullOrEmpty(Msbuild16Path))
53
{
53
- Msbuild16Path = path;
54
+ var path = Path.Combine(installPath, Msbuild16RelativePath);
55
+ if (File.Exists(path))
56
+ {
57
+ Msbuild16Path = path;
58
+ }
59
}
55
- }
60
57
- if (String.IsNullOrEmpty(Msbuild15Path))
58
- {
59
- var path = Path.Combine(installPath, Msbuild15RelativePath);
60
- if (File.Exists(path))
61
+ if (String.IsNullOrEmpty(Msbuild15Path))
62
{
62
- Msbuild15Path = path;
63
+ var path = Path.Combine(installPath, Msbuild15RelativePath);
64
+ if (File.Exists(path))
65
+ {
66
+ Msbuild15Path = path;
67
+ }
68
}
69
}
70
}