@@ -14,13 +14,13 @@ public class VSTestForwardingApp : ForwardingApp
14
14
public VSTestForwardingApp ( IEnumerable < string > argsToForward )
15
15
: base ( GetVSTestExePath ( ) , argsToForward )
16
16
{
17
- ( bool hasRootVariable , string rootVariableName , string rootValue ) = GetRootVariable ( ) ;
18
- if ( ! hasRootVariable )
17
+ Dictionary < string , string > variables = GetVSTestRootVariables ( ) ;
18
+ foreach ( var ( rootVariableName , rootValue ) in variables )
19
19
{
20
20
WithEnvironmentVariable ( rootVariableName , rootValue ) ;
21
21
VSTestTrace . SafeWriteTrace ( ( ) => $ "Root variable set { rootVariableName } :{ rootValue } ") ;
22
22
}
23
-
23
+
24
24
VSTestTrace . SafeWriteTrace ( ( ) => $ "Forwarding to '{ GetVSTestExePath ( ) } ' with args \" { argsToForward ? . Aggregate ( ( a , b ) => $ "{ a } | { b } ") } \" ") ;
25
25
}
26
26
@@ -38,14 +38,17 @@ private static string GetVSTestExePath()
38
38
return Path . Combine ( AppContext . BaseDirectory , VstestAppName ) ;
39
39
}
40
40
41
- internal static ( bool hasRootVariable , string rootVariableName , string rootValue ) GetRootVariable ( )
41
+ internal static Dictionary < string , string > GetVSTestRootVariables ( )
42
42
{
43
- string rootVariableName = Environment . Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)" ;
44
- bool hasRootVariable = Environment . GetEnvironmentVariable ( rootVariableName ) != null ;
45
- string rootValue = hasRootVariable ? null : Path . GetDirectoryName ( new Muxer ( ) . MuxerPath ) ;
46
-
47
- // We rename env variable to support --arch switch that relies on DOTNET_ROOT/DOTNET_ROOT(x86)
48
- // We provide VSTEST_WINAPPHOST_ only in case of testhost*.exe removing VSTEST_WINAPPHOST_ prefix and passing as env vars.
49
- return ( hasRootVariable , $ "VSTEST_WINAPPHOST_{ rootVariableName } ", rootValue ) ;
43
+ // Gather the current .NET SDK dotnet.exe location and forward it to vstest.console.dll so it can use it
44
+ // to setup DOTNET_ROOT for testhost.exe, to find the same installation of NET SDK that is running `dotnet test`.
45
+ // This way if we have private installation of .NET SDK, the testhost.exe will be able to use the same private installation.
46
+ // The way to set the environment is complicated and depends on the version of testhost, so we leave that implementation to vstest console,
47
+ // we just tell it where the current .net SDK is located, and what is the architecture of it. We don't have more information than that here.
48
+ return new ( )
49
+ {
50
+ [ "VSTEST_DOTNET_ROOT_PATH" ] = Path . GetDirectoryName ( new Muxer ( ) . MuxerPath ) ,
51
+ [ "VSTEST_DOTNET_ROOT_ARCHITECTURE" ] = RuntimeInformation . ProcessArchitecture . ToString ( )
52
+ } ;
50
53
}
51
54
}
0 commit comments