diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs
index 7386f07d06..f3d38c923a 100644
--- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs
+++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs
@@ -40,9 +40,19 @@ public ConsoleParameters(IFileHelper fileHelper)
}
///
- /// Environment variables to be set for the process
+ /// Environment variables to be set for the process. This will merge the specified entries to the environment variables
+ /// inherited from the current process. If you wish to provide a full set of environment variables yourself set to false.
///
- public Dictionary EnvironmentVariables { get; set; }
+ public Dictionary EnvironmentVariables { get; set; } = new Dictionary();
+
+ ///
+ /// When set to true (default), all environment variables are inherited from the current process and the entries provided in are merged with that set.
+ /// When set to false, only the values you provide in are used. Giving you full control of the environment vstest.console is started with.
+ /// This is only rarely useful and can lead to vstest.console not being able to start at all.
+ /// You most likely want to use and combine
+ /// and responses.
+ ///
+ public bool InheritEnvironmentVariables { get; set; } = true;
///
/// Trace level for logs.
diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/PublicAPI.Shipped.txt
index e9c4b6ee04..e8f1f17352 100644
--- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/PublicAPI.Shipped.txt
+++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/PublicAPI/PublicAPI.Shipped.txt
@@ -199,3 +199,5 @@ static Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Resour
virtual Microsoft.TestPlatform.VsTestConsole.TranslationLayer.TestSession.Dispose(bool disposing) -> void
Microsoft.TestPlatform.VsTestConsole.TranslationLayer.ConsoleParameters.EnvironmentVariables.get -> System.Collections.Generic.Dictionary
Microsoft.TestPlatform.VsTestConsole.TranslationLayer.ConsoleParameters.EnvironmentVariables.set -> void
+Microsoft.TestPlatform.VsTestConsole.TranslationLayer.ConsoleParameters.InheritEnvironmentVariables.get -> bool
+Microsoft.TestPlatform.VsTestConsole.TranslationLayer.ConsoleParameters.InheritEnvironmentVariables.set -> void
diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs
index 323ff2d95a..c76e6e1d1b 100644
--- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs
+++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs
@@ -119,16 +119,25 @@ public void StartProcess(ConsoleParameters consoleParameters)
RedirectStandardError = true
};
- EqtTrace.Verbose("VsTestCommandLineWrapper: Process Start Info {0} {1}", info.FileName, info.Arguments);
+ EqtTrace.Verbose("VsTestCommandLineWrapper.StartProcess: Process Start Info {0} {1}", info.FileName, info.Arguments);
- if (consoleParameters.EnvironmentVariables != null)
+ if (!consoleParameters.InheritEnvironmentVariables)
{
+ EqtTrace.Verbose("VsTestCommandLineWrapper.StartProcess: Clearing all environment variables.");
+
info.EnvironmentVariables.Clear();
+ }
+
+ if (consoleParameters.EnvironmentVariables != null)
+ {
foreach (var envVariable in consoleParameters.EnvironmentVariables)
{
if (envVariable.Key != null)
{
- info.EnvironmentVariables.Add(envVariable.Key, envVariable.Value?.ToString());
+ // Not printing the value on purpose, env variables can contain secrets and we don't need to know the values
+ // most of the time.
+ EqtTrace.Verbose("VsTestCommandLineWrapper.StartProcess: Setting environment variable: {0}", envVariable.Key);
+ info.EnvironmentVariables[envVariable.Key] = envVariable.Value?.ToString();
}
}
}