From 1a731fb70c36b227359012fbceb622623b768d79 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Thu, 29 Sep 2022 11:12:53 +0000 Subject: [PATCH] [wasm] fix weird build failures `MSBuildSDKsPath` is set by runtime repo, and that interferes with the test projects. To avoid this the `MSBuildSDKsPath` was set to `""` in the test environment. But even that can negatively affect the build because msbuild treats environment variables as "global properties" that cannot be changed. This manifests when running: `$ dotnet run --no-build` .. it would fail with `/foo/bar.csproj is not a valid project file`. Instead, explicitly *remove* `MSBuildSDKsPath` from the environment when invoking the process. --- src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs | 1 - src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 3 +++ src/mono/wasm/Wasm.Build.Tests/HelperExtensions.cs | 13 +++++++++++++ src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs b/src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs index 62f7cc4d762ba..de8c14b30495b 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs @@ -107,7 +107,6 @@ public BuildEnvironment() EnvVars["DOTNET_INSTALL_DIR"] = sdkForWorkloadPath; EnvVars["DOTNET_MULTILEVEL_LOOKUP"] = "0"; EnvVars["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1"; - EnvVars["MSBuildSDKsPath"] = string.Empty; EnvVars["PATH"] = $"{sdkForWorkloadPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}"; EnvVars["EM_WORKAROUND_PYTHON_BUG_34780"] = "1"; diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index d6b4d26f3532e..7847c95cfc374 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -840,6 +840,9 @@ public static (int exitCode, string buildOutput) RunProcess(string path, processStartInfo.EnvironmentVariables[envVar.Key] = envVar.Value; _testOutput.WriteLine($"\t{envVar.Key} = {envVar.Value}"); } + + // runtime repo sets this, which interferes with the tests + processStartInfo.RemoveEnvironmentVariables("MSBuildSDKsPath"); } Process process = new (); diff --git a/src/mono/wasm/Wasm.Build.Tests/HelperExtensions.cs b/src/mono/wasm/Wasm.Build.Tests/HelperExtensions.cs index 11710c3bd1bea..7f36db407e2dd 100644 --- a/src/mono/wasm/Wasm.Build.Tests/HelperExtensions.cs +++ b/src/mono/wasm/Wasm.Build.Tests/HelperExtensions.cs @@ -120,5 +120,18 @@ public static void UpdateTo(this IDictionary string.Compare(k, name, StringComparison.OrdinalIgnoreCase) == 0); + if (key is not null) + env.Remove("MSBuildSDKsPath"); + } + + return psi; + } } } diff --git a/src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs b/src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs index a3438f707c4d2..2fae80aa4bdd3 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ToolCommand.cs @@ -161,6 +161,8 @@ private Process CreateProcess(string executable, string args) psi.Environment["DOTNET_MULTILEVEL_LOOKUP"] = "0"; psi.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1"; + // runtime repo sets this, which interferes with the tests + psi.RemoveEnvironmentVariables("MSBuildSDKsPath"); AddEnvironmentVariablesTo(psi); AddWorkingDirectoryTo(psi); var process = new Process @@ -201,6 +203,7 @@ private void AddEnvironmentVariablesTo(ProcessStartInfo psi) { foreach (var item in Environment) { + _testOutput.WriteLine($"\t[{item.Key}] = {item.Value}"); psi.Environment[item.Key] = item.Value; } }