Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup tmp code for the --arch feature #3174

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.LogFile.
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.get -> System.Diagnostics.TraceLevel
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.set -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.AddEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name, string value) -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.RemoveEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.LogFile.
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.get -> System.Diagnostics.TraceLevel
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.set -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.AddEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name, string value) -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.RemoveEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.LogFile.
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.get -> System.Diagnostics.TraceLevel
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.set -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.AddEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name, string value) -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.RemoveEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.LogFile.
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.get -> System.Diagnostics.TraceLevel
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.set -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.AddEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name, string value) -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.RemoveEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.LogFile.
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.get -> System.Diagnostics.TraceLevel
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.set -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.AddEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name, string value) -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.RemoveEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.LogFile.
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.get -> System.Diagnostics.TraceLevel
static Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.TraceLevel.set -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.AddEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name, string value) -> void
static Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessStartInfoExtensions.RemoveEnvironmentVariable(this System.Diagnostics.ProcessStartInfo startInfo, string name) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public object LaunchProcess(string processPath, string arguments, string working
}
}

// VSTEST_WINAPPHOST_DOTNET_ROOT is made to flow by SDK to support apphost and --arch feature
// we remove to not pollute host process environment variables
process.StartInfo.RemoveEnvironmentVariable("VSTEST_WINAPPHOST_DOTNET_ROOT");
MarcoRossignoli marked this conversation as resolved.
Show resolved Hide resolved

if (outputCallBack != null)
{
process.StartInfo.RedirectStandardOutput = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public static void AddEnvironmentVariable(this ProcessStartInfo startInfo, strin
{
startInfo.EnvironmentVariables[name] = value;
}

/// <summary>
/// Remove environment variable that apply to this process and child processes.
/// </summary>
/// <param name="startInfo">The process start info</param>
/// <param name="name">Environment Variable name.</param>
public static void RemoveEnvironmentVariable(this ProcessStartInfo startInfo, string name)
{
startInfo.EnvironmentVariables.Remove(name);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public static void AddEnvironmentVariable(this ProcessStartInfo startInfo, strin
{
startInfo.Environment[name] = value;
}

/// <summary>
/// Remove environment variable that apply to this process and child processes.
/// </summary>
/// <param name="startInfo">The process start info</param>
/// <param name="name">Environment Variable name.</param>
public static void RemoveEnvironmentVariable(this ProcessStartInfo startInfo, string name)
{
startInfo.Environment.Remove(name);
}
}
}

Expand Down
39 changes: 0 additions & 39 deletions src/vstest.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,8 @@ public static class Program
public static int Main(string[] args)
{
DebuggerBreakpoint.WaitForDebugger("VSTEST_RUNNER_DEBUG");
ForwardDotnetRootEnvVarToNewVersion();
UILanguageOverride.SetCultureSpecifiedByUser();
return new Executor(ConsoleOutput.Instance).Execute(args);
}

/// <summary>
/// Forwarding of DOTNET_ROOT/DOTNET_ROOT(x86) env vars populted by SDK, this is needed to allow to --arch feature to work
/// as expected. If we use old SDK and new TP it won't work without env vars forwarding.
/// </summary>
private static void ForwardDotnetRootEnvVarToNewVersion()
{
// TODO: remove this and the console writes before publishing
var switchVars = Environment.GetEnvironmentVariable("VSTEST_TMP_SWITCH_DOTNETROOTS_ENVVARS");
if (switchVars != null && int.Parse(switchVars) == 1)
{
var dotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");
if (dotnetRoot != null)
{
# if DEBUG
Console.WriteLine($"Forwarding DOTNET_ROOT to VSTEST_WINAPPHOST_DOTNET_ROOT '{dotnetRoot}'");
#endif
Environment.SetEnvironmentVariable("DOTNET_ROOT", null);
Environment.SetEnvironmentVariable("VSTEST_WINAPPHOST_DOTNET_ROOT", dotnetRoot);
#if DEBUG
Console.WriteLine($"Current DOTNET_ROOT '{Environment.GetEnvironmentVariable("DOTNET_ROOT")}'");
#endif
}

var dotnetRootX86 = Environment.GetEnvironmentVariable("DOTNET_ROOT(x86)");
if(dotnetRootX86 != null)
{
#if DEBUG
Console.WriteLine($"Forwarding DOTNET_ROOT(x86) to VSTEST_WINAPPHOST_DOTNET_ROOT(x86) '{dotnetRootX86}'");
#endif
Environment.SetEnvironmentVariable("DOTNET_ROOT(x86)", null);
Environment.SetEnvironmentVariable("VSTEST_WINAPPHOST_DOTNET_ROOT(x86)", dotnetRootX86);
#if DEBUG
Console.WriteLine($"Current DOTNET_ROOT(x86) '{Environment.GetEnvironmentVariable("DOTNET_ROOT(x86)")}'");
#endif
}
}
}
}
}