From 2ab17d9c527629fa70ee4dec81bd0050e1b27f31 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 10 May 2020 14:32:18 +1000 Subject: Put lock around locating msbuild. --- src/WixBuildTools.TestSupport/MsbuildRunner.cs | 53 ++++++++++++++------------ 1 file 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 private static readonly string Msbuild15RelativePath = @"MSBuild\15.0\Bin\MSBuild.exe"; private static readonly string Msbuild16RelativePath = @"MSBuild\Current\Bin\MSBuild.exe"; + private static readonly object InitLock = new object(); + private static string Msbuild15Path; private static string Msbuild16Path; @@ -26,40 +28,43 @@ namespace WixBuildTools.TestSupport private static MsbuildRunnerResult InitAndExecute(string msbuildVersion, string projectPath, string[] arguments) { - if (Msbuild15Path == null && Msbuild16Path == null) + lock (InitLock) { - var vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), VswhereRelativePath); - if (!File.Exists(vswherePath)) + if (Msbuild15Path == null && Msbuild16Path == null) { - throw new InvalidOperationException($"Failed to find vswhere at: {vswherePath}"); - } + var vswherePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), VswhereRelativePath); + if (!File.Exists(vswherePath)) + { + throw new InvalidOperationException($"Failed to find vswhere at: {vswherePath}"); + } - var result = RunProcessCaptureOutput(vswherePath, VswhereFindArguments); - if (result.ExitCode != 0) - { - throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {result.ExitCode}"); - } + var result = RunProcessCaptureOutput(vswherePath, VswhereFindArguments); + if (result.ExitCode != 0) + { + throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {result.ExitCode}"); + } - Msbuild15Path = String.Empty; - Msbuild16Path = String.Empty; + Msbuild15Path = String.Empty; + Msbuild16Path = String.Empty; - foreach (var installPath in result.Output) - { - if (String.IsNullOrEmpty(Msbuild16Path)) + foreach (var installPath in result.Output) { - var path = Path.Combine(installPath, Msbuild16RelativePath); - if (File.Exists(path)) + if (String.IsNullOrEmpty(Msbuild16Path)) { - Msbuild16Path = path; + var path = Path.Combine(installPath, Msbuild16RelativePath); + if (File.Exists(path)) + { + Msbuild16Path = path; + } } - } - if (String.IsNullOrEmpty(Msbuild15Path)) - { - var path = Path.Combine(installPath, Msbuild15RelativePath); - if (File.Exists(path)) + if (String.IsNullOrEmpty(Msbuild15Path)) { - Msbuild15Path = path; + var path = Path.Combine(installPath, Msbuild15RelativePath); + if (File.Exists(path)) + { + Msbuild15Path = path; + } } } } -- cgit v1.2.3-55-g6feb