@@ -13,8 +13,8 @@ public class VSTestForwardingApp : ForwardingApp
1313 public VSTestForwardingApp ( IEnumerable < string > argsToForward )
1414 : base ( GetVSTestExePath ( ) , argsToForward )
1515 {
16- ( bool hasRootVariable , string rootVariableName , string rootValue ) = GetRootVariable ( ) ;
17- if ( ! hasRootVariable )
16+ Dictionary < string , string > variables = GetVSTestRootVariables ( ) ;
17+ foreach ( var ( rootVariableName , rootValue ) in variables )
1818 {
1919 WithEnvironmentVariable ( rootVariableName , rootValue ) ;
2020 VSTestTrace . SafeWriteTrace ( ( ) => $ "Root variable set { rootVariableName } :{ rootValue } ") ;
@@ -37,15 +37,18 @@ private static string GetVSTestExePath()
3737 return Path . Combine ( AppContext . BaseDirectory , VstestAppName ) ;
3838 }
3939
40- internal static ( bool hasRootVariable , string rootVariableName , string rootValue ) GetRootVariable ( )
40+ internal static Dictionary < string , string > GetVSTestRootVariables ( )
4141 {
42- string rootVariableName = Environment . Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)" ;
43- bool hasRootVariable = Environment . GetEnvironmentVariable ( rootVariableName ) != null ;
44- string rootValue = hasRootVariable ? null : Path . GetDirectoryName ( new Muxer ( ) . MuxerPath ) ;
45-
46- // We rename env variable to support --arch switch that relies on DOTNET_ROOT/DOTNET_ROOT(x86)
47- // We provide VSTEST_WINAPPHOST_ only in case of testhost*.exe removing VSTEST_WINAPPHOST_ prefix and passing as env vars.
48- return ( hasRootVariable , $ "VSTEST_WINAPPHOST_{ rootVariableName } ", rootValue ) ;
42+ // Gather the current .NET SDK dotnet.exe location and forward it to vstest.console.dll so it can use it
43+ // to setup DOTNET_ROOT for testhost.exe, to find the same installation of NET SDK that is running `dotnet test`.
44+ // This way if we have private installation of .NET SDK, the testhost.exe will be able to use the same private installation.
45+ // The way to set the environment is complicated and depends on the version of testhost, so we leave that implementation to vstest console,
46+ // 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.
47+ return new ( )
48+ {
49+ [ "VSTEST_DOTNET_ROOT_PATH" ] = Path . GetDirectoryName ( new Muxer ( ) . MuxerPath ) ,
50+ [ "VSTEST_DOTNET_ROOT_ARCHITECTURE" ] = RuntimeInformation . ProcessArchitecture . ToString ( )
51+ } ;
4952 }
5053 }
5154}
0 commit comments