Skip to content

Commit 7d28e20

Browse files
singhsarabcltshivash
authored andcommitted
[Draft] [Design mode] Invoking vstest.console with environment variables (#2023)
* Changes to allow clients to provide environment variable while initializing VsTestConsoleWrapper * Changes based on comments.
1 parent 93ffe26 commit 7d28e20

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/ConsoleParameters.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer
55
{
66
using System;
7+
using System.Collections.Generic;
78
using System.Diagnostics;
89
using System.IO;
910

@@ -37,6 +38,16 @@ public ConsoleParameters(IFileHelper fileHelper)
3738
this.fileHelper = fileHelper;
3839
}
3940

41+
#if NET451
42+
43+
/// <summary>
44+
/// TODO: Remove the #if when project is targeted to netstandard2.0
45+
/// Environment variables to be set for the process
46+
/// </summary>
47+
public Dictionary<string, string> EnvironmentVariables { get; set; }
48+
49+
#endif
50+
4051
/// <summary>
4152
/// Trace level for logs.
4253
/// </summary>

src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleProcessManager.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer
99
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
1010
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
1111
using System;
12+
using System.Collections;
1213
using System.Collections.Generic;
1314
using System.Diagnostics;
1415
using System.Globalization;
@@ -106,6 +107,19 @@ public void StartProcess(ConsoleParameters consoleParameters)
106107

107108
EqtTrace.Verbose("VsTestCommandLineWrapper: Process Start Info {0} {1}", info.FileName, info.Arguments);
108109

110+
#if NET451
111+
if (consoleParameters.EnvironmentVariables != null)
112+
{
113+
info.EnvironmentVariables.Clear();
114+
foreach (var envVariable in consoleParameters.EnvironmentVariables)
115+
{
116+
if (envVariable.Key != null)
117+
{
118+
info.EnvironmentVariables.Add(envVariable.Key.ToString(), envVariable.Value?.ToString());
119+
}
120+
}
121+
}
122+
#endif
109123
this.process = Process.Start(info);
110124
this.process.Start();
111125

0 commit comments

Comments
 (0)