diff --git a/src/installer/test/HostActivation.Tests/CommandExtensions.cs b/src/installer/test/HostActivation.Tests/CommandExtensions.cs index 267d185b2f7..edff69a88f3 100644 --- a/src/installer/test/HostActivation.Tests/CommandExtensions.cs +++ b/src/installer/test/HostActivation.Tests/CommandExtensions.cs @@ -36,6 +36,18 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation .CaptureStdErr(); } + public static Command DotNetRoot(this Command command, string dotNetRoot) + { + return command + .EnvironmentVariable("DOTNET_ROOT", dotNetRoot) + .EnvironmentVariable("DOTNET_ROOT(x86)", dotNetRoot); + } + + public static Command MultilevelLookup(this Command command, bool enable) + { + return command.EnvironmentVariable(Constants.MultilevelLookup.EnvironmentVariable, enable ? "1" : "0"); + } + public static Command RuntimeId(this Command command, string rid) { return command.EnvironmentVariable(Constants.RuntimeId.EnvironmentVariable, rid); diff --git a/src/installer/test/HostActivation.Tests/DependencyResolution/ComponentDependencyResolutionBase.cs b/src/installer/test/HostActivation.Tests/DependencyResolution/ComponentDependencyResolutionBase.cs index 4dcdfc77995..983a07a1597 100644 --- a/src/installer/test/HostActivation.Tests/DependencyResolution/ComponentDependencyResolutionBase.cs +++ b/src/installer/test/HostActivation.Tests/DependencyResolution/ComponentDependencyResolutionBase.cs @@ -60,7 +60,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution }; Command command = Command.Create(NativeHostPath, args) - .EnableTracingAndCaptureOutputs(); + .EnableTracingAndCaptureOutputs() + .MultilevelLookup(false); commandCustomizer?.Invoke(command); return command.Execute() @@ -86,6 +87,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution return Command.Create(NativeHostPath, args) .EnableTracingAndCaptureOutputs() + .MultilevelLookup(false) .Execute(); } diff --git a/src/installer/test/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs b/src/installer/test/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs index c0ab4241a60..9bf520d508b 100644 --- a/src/installer/test/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs +++ b/src/installer/test/HostActivation.Tests/FrameworkResolution/FrameworkResolutionBase.cs @@ -46,11 +46,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.FrameworkResolution } CommandResult result = command - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", multiLevelLookup ? "1" : "0") + .EnableTracingAndCaptureOutputs() + .MultilevelLookup(multiLevelLookup) .Environment(settings.Environment) - .CaptureStdOut() - .CaptureStdErr() .Execute(); resultAction?.Invoke(result); diff --git a/src/installer/test/HostActivation.Tests/MockCoreClrSanity.cs b/src/installer/test/HostActivation.Tests/MockCoreClrSanity.cs index 73aaa3b0678..3890c2049c7 100644 --- a/src/installer/test/HostActivation.Tests/MockCoreClrSanity.cs +++ b/src/installer/test/HostActivation.Tests/MockCoreClrSanity.cs @@ -54,6 +54,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation DotNet.Exec("--roll-forward-on-no-candidate-fx", "2", appDll, "argumentOne", "arg2") .CaptureStdOut() .CaptureStdErr() + .MultilevelLookup(false) .Execute() .Should().Pass() .And.HaveStdOutContaining("mock coreclr_initialize() called") diff --git a/src/installer/test/HostActivation.Tests/NativeHosting/Comhost.cs b/src/installer/test/HostActivation.Tests/NativeHosting/Comhost.cs index 1ebc2cb4d7a..115fc428aa7 100644 --- a/src/installer/test/HostActivation.Tests/NativeHosting/Comhost.cs +++ b/src/installer/test/HostActivation.Tests/NativeHosting/Comhost.cs @@ -31,12 +31,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting return; } - string scenario = synchronous ? "synchronous" : "concurrent"; - string args = $"comhost {scenario} {count} {sharedState.ComHostPath} {sharedState.ClsidString}"; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .EnableTracingAndCaptureOutputs() - .EnvironmentVariable("DOTNET_ROOT", sharedState.ComLibraryFixture.BuiltDotnet.BinPath) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.ComLibraryFixture.BuiltDotnet.BinPath) + string [] args = { + "comhost", + synchronous ? "synchronous" : "concurrent", + $"{count}", + sharedState.ComHostPath, + sharedState.ClsidString + }; + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.ComLibraryFixture.BuiltDotnet.BinPath) .Execute(); result.Should().Pass() @@ -64,11 +66,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting fixture.TestProject.BuiltApp.Location, $"{ fixture.TestProject.AssemblyName }.comhost.dll"); - string args = $"comhost synchronous 1 {comHostWithAppLocalFxr} {sharedState.ClsidString}"; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .EnableTracingAndCaptureOutputs() - .EnvironmentVariable("DOTNET_ROOT", fixture.BuiltDotnet.BinPath) - .EnvironmentVariable("DOTNET_ROOT(x86)", fixture.BuiltDotnet.BinPath) + string[] args = { + "comhost", + "synchronous", + "1", + comHostWithAppLocalFxr, + sharedState.ClsidString + }; + CommandResult result = sharedState.CreateNativeHostCommand(args, fixture.BuiltDotnet.BinPath) .Execute(); result.Should().Pass() @@ -98,11 +103,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting fixture.TestProject.BuiltApp.Location, $"{ fixture.TestProject.AssemblyName }.comhost.dll"); - string args = $"comhost errorinfo 1 {comHost} {sharedState.ClsidString}"; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .EnableTracingAndCaptureOutputs() - .EnvironmentVariable("DOTNET_ROOT", fixture.BuiltDotnet.BinPath) - .EnvironmentVariable("DOTNET_ROOT(x86)", fixture.BuiltDotnet.BinPath) + string[] args = { + "comhost", + "errorinfo", + "1", + comHost, + sharedState.ClsidString + }; + CommandResult result = sharedState.CreateNativeHostCommand(args, fixture.BuiltDotnet.BinPath) .Execute(); result.Should().Pass() diff --git a/src/installer/test/HostActivation.Tests/NativeHosting/ComponentActivation.cs b/src/installer/test/HostActivation.Tests/NativeHosting/ComponentActivation.cs index e56be297b5a..27aa0c54610 100644 --- a/src/installer/test/HostActivation.Tests/NativeHosting/ComponentActivation.cs +++ b/src/installer/test/HostActivation.Tests/NativeHosting/ComponentActivation.cs @@ -38,12 +38,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting validType ? sharedState.ComponentTypeName : $"Component.BadType, {componentProject.AssemblyName}", validMethod ? sharedState.ComponentEntryPoint1 : "BadMethod", }; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .Execute(); result.Should() @@ -90,12 +85,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting args = args.Concat(componentInfo); } - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .Execute(); result.Should().Pass() @@ -139,12 +129,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting args = args.Concat(componentInfo); } - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .Execute(); result.Should().Pass() diff --git a/src/installer/test/HostActivation.Tests/NativeHosting/HostContext.cs b/src/installer/test/HostActivation.Tests/NativeHosting/HostContext.cs index bac6d98dd21..b18b59c8e3f 100644 --- a/src/installer/test/HostActivation.Tests/NativeHosting/HostContext.cs +++ b/src/installer/test/HostActivation.Tests/NativeHosting/HostContext.cs @@ -138,12 +138,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting SharedTestState.AppPropertyName, newPropertyName }; - CommandResult result = Command.Create(sharedState.NativeHostPath, args.Concat(commandArgs).Concat(appArgs)) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args.Concat(commandArgs).Concat(appArgs), sharedState.DotNetRoot) .Execute(); result.Should().Pass() @@ -176,12 +171,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting SharedTestState.ConfigPropertyName, newPropertyName }; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .Execute(); result.Should().Pass() @@ -203,12 +193,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting sharedState.SelfContainedHostFxrPath, sharedState.SelfContainedConfigPath }; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .Execute(); result.Should().Fail() @@ -236,12 +221,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting SharedTestState.ConfigPropertyName, SharedTestState.SecondaryConfigPropertyName }; - CommandResult result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) + CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .Execute(); result.Should().Pass() @@ -289,13 +269,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting SharedTestState.AppPropertyName, SharedTestState.ConfigPropertyName }; - CommandResult result = Command.Create(sharedState.NativeHostPath, args.Concat(appArgs)) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") + CommandResult result = sharedState.CreateNativeHostCommand(args.Concat(appArgs), sharedState.DotNetRoot) .EnvironmentVariable("COREHOST_TRACE_VERBOSITY", "3") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) .EnvironmentVariable("TEST_BLOCK_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.block") .EnvironmentVariable("TEST_SIGNAL_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.signal") .Execute(); @@ -380,13 +355,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting CommandResult result; try { - result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") + result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .EnvironmentVariable("COREHOST_TRACE_VERBOSITY", "3") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) .EnvironmentVariable("TEST_BLOCK_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.block") .EnvironmentVariable("TEST_SIGNAL_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.signal") .Execute(); @@ -476,13 +446,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting CommandResult result; try { - result = Command.Create(sharedState.NativeHostPath, args) - .CaptureStdErr() - .CaptureStdOut() - .EnvironmentVariable("COREHOST_TRACE", "1") + result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) .EnvironmentVariable("COREHOST_TRACE_VERBOSITY", "3") - .EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot) .EnvironmentVariable("TEST_BLOCK_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.block") .EnvironmentVariable("TEST_SIGNAL_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.signal") .Execute(); diff --git a/src/installer/test/HostActivation.Tests/NativeHosting/Nethost.cs b/src/installer/test/HostActivation.Tests/NativeHosting/Nethost.cs index dbf23d94b5e..944a03d9177 100644 --- a/src/installer/test/HostActivation.Tests/NativeHosting/Nethost.cs +++ b/src/installer/test/HostActivation.Tests/NativeHosting/Nethost.cs @@ -35,8 +35,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting string dotNetRoot = isValid ? Path.Combine(sharedState.ValidInstallRoot, "dotnet") : sharedState.InvalidInstallRoot; CommandResult result = Command.Create(sharedState.NativeHostPath, $"{GetHostFxrPath} {explicitLoad} {(useAssemblyPath ? sharedState.TestAssemblyPath : string.Empty)}") .EnableTracingAndCaptureOutputs() - .EnvironmentVariable("DOTNET_ROOT", dotNetRoot) - .EnvironmentVariable("DOTNET_ROOT(x86)", dotNetRoot) + .DotNetRoot(dotNetRoot) .Execute(); result.Should().HaveStdErrContaining("Using environment variable"); diff --git a/src/installer/test/HostActivation.Tests/NativeHosting/SharedTestStateBase.cs b/src/installer/test/HostActivation.Tests/NativeHosting/SharedTestStateBase.cs index e0f56bcf2b0..8821583cd07 100644 --- a/src/installer/test/HostActivation.Tests/NativeHosting/SharedTestStateBase.cs +++ b/src/installer/test/HostActivation.Tests/NativeHosting/SharedTestStateBase.cs @@ -2,7 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.DotNet.Cli.Build.Framework; using System; +using System.Collections.Generic; using System.IO; namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting @@ -37,6 +39,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting NethostPath); } + public Command CreateNativeHostCommand(IEnumerable args, string dotNetRoot) + { + return Command.Create(NativeHostPath, args) + .EnableTracingAndCaptureOutputs() + .DotNetRoot(dotNetRoot) + .MultilevelLookup(false); + } + public void Dispose() { Dispose(true); diff --git a/src/installer/test/HostActivation.Tests/PortableAppActivation.cs b/src/installer/test/HostActivation.Tests/PortableAppActivation.cs index e1155e78f5d..3f429d0b6eb 100644 --- a/src/installer/test/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/test/HostActivation.Tests/PortableAppActivation.cs @@ -150,10 +150,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation "exec", "--additionalprobingpath", additionalProbingPath, appDll) - .EnvironmentVariable("COREHOST_TRACE", "1") - .EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") - .CaptureStdErr() - .CaptureStdOut() + .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") @@ -279,8 +276,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() - .EnvironmentVariable("DOTNET_ROOT", builtDotnet) - .EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet) + .DotNetRoot(builtDotnet) + .MultilevelLookup(false) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") @@ -290,8 +287,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation // Verify running from within the working directory Command.Create(appExe) .WorkingDirectory(fixture.TestProject.OutputDirectory) - .EnvironmentVariable("DOTNET_ROOT", builtDotnet) - .EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet) + .DotNetRoot(builtDotnet) + .MultilevelLookup(false) .CaptureStdErr() .CaptureStdOut() .Execute() @@ -347,6 +344,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() + .MultilevelLookup(false) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) .Execute() @@ -358,6 +356,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() + .MultilevelLookup(false) .WorkingDirectory(fixture.TestProject.OutputDirectory) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) @@ -378,9 +377,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation var appDll = fixture.TestProject.AppDll; dotnet.Exec(appDll) - .EnvironmentVariable("COREHOST_TRACE", "1") - .CaptureStdErr() - .CaptureStdOut() + .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() .And.HaveStdErrMatching($"Property TRUSTED_PLATFORM_ASSEMBLIES = .*[^{Path.PathSeparator}]$", System.Text.RegularExpressions.RegexOptions.Multiline); diff --git a/src/installer/test/TestUtils/DotNetCli.cs b/src/installer/test/TestUtils/DotNetCli.cs index aa713b22982..5f2730da0e6 100644 --- a/src/installer/test/TestUtils/DotNetCli.cs +++ b/src/installer/test/TestUtils/DotNetCli.cs @@ -67,7 +67,8 @@ namespace Microsoft.DotNet.Cli.Build } return Command.Create(DotnetExecutablePath, newArgs) - .EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1"); + .EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1") + .EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0"); // Avoid looking at machine state by default } public Command Restore(params string[] args) => Exec("restore", args);