@@ -67,6 +67,8 @@ public class DotnetTestHostManager : ITestRuntimeProvider
6767
6868 private Architecture architecture ;
6969
70+ private bool isVersionCheckRequired = true ;
71+
7072 /// <summary>
7173 /// Initializes a new instance of the <see cref="DotnetTestHostManager"/> class.
7274 /// </summary>
@@ -111,8 +113,20 @@ internal DotnetTestHostManager(
111113
112114 /// <summary>
113115 /// Gets a value indicating whether the test host supports protocol version check
116+ /// By default this is set to true. For host package version 15.0.0, this will be set to false;
114117 /// </summary>
115- internal virtual bool IsVersionCheckRequired => ! this . hostPackageVersion . StartsWith ( "15.0.0" ) ;
118+ internal virtual bool IsVersionCheckRequired
119+ {
120+ get
121+ {
122+ return this . isVersionCheckRequired ;
123+ }
124+
125+ private set
126+ {
127+ this . isVersionCheckRequired = value ;
128+ }
129+ }
116130
117131 /// <summary>
118132 /// Gets a value indicating whether the test host supports protocol version check
@@ -203,14 +217,46 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
203217 EqtTrace . Verbose ( "DotnetTestHostmanager: File {0}, doesnot exist" , depsFilePath ) ;
204218 }
205219
206- // If Testhost.exe is available use it
207- var exeName = this . architecture == Architecture . X86 ? "testhost.x86.exe" : "testhost.exe" ;
208- var fullExePath = Path . Combine ( sourceDirectory , exeName ) ;
209- if ( this . platformEnvironment . OperatingSystem . Equals ( PlatformOperatingSystem . Windows ) && this . fileHelper . Exists ( fullExePath ) )
220+ var runtimeConfigDevPath = Path . Combine ( sourceDirectory , string . Concat ( sourceFile , ".runtimeconfig.dev.json" ) ) ;
221+ string testHostPath = string . Empty ;
222+
223+ // If testhost.exe is available use it
224+ bool testHostExeFound = false ;
225+ if ( this . platformEnvironment . OperatingSystem . Equals ( PlatformOperatingSystem . Windows ) )
210226 {
211- startInfo . FileName = fullExePath ;
227+ var exeName = this . architecture == Architecture . X86 ? "testhost.x86.exe" : "testhost.exe" ;
228+ var fullExePath = Path . Combine ( sourceDirectory , exeName ) ;
229+
230+ // check for testhost.exe in sourceDirectory. If not found, check in nuget folder.
231+ if ( this . fileHelper . Exists ( fullExePath ) )
232+ {
233+ EqtTrace . Verbose ( "DotnetTestHostManager: Testhost.exe/testhost.x86.exe found at path: " + fullExePath ) ;
234+ startInfo . FileName = fullExePath ;
235+ testHostExeFound = true ;
236+ }
237+ else
238+ {
239+ // Check if testhost.dll is found in nuget folder.
240+ testHostPath = this . GetTestHostPath ( runtimeConfigDevPath , depsFilePath , sourceDirectory ) ;
241+ if ( testHostPath . IndexOf ( "microsoft.testplatform.testhost" , StringComparison . OrdinalIgnoreCase ) >= 0 )
242+ {
243+ // testhost.dll is present in path {testHostNugetRoot}\lib\netcoreapp2.1\testhost.dll
244+ // testhost.(x86).exe is present in location {testHostNugetRoot}\build\netcoreapp2.1\{x86/x64}\{testhost.x86.exe/testhost.exe}
245+ var folderName = this . architecture == Architecture . X86 ? "x86" : "x64" ;
246+ var testHostNugetRoot = new DirectoryInfo ( testHostPath ) . Parent . Parent . Parent ;
247+ var testHostExeNugetPath = Path . Combine ( testHostNugetRoot . FullName , "build" , "netcoreapp2.1" , folderName , exeName ) ;
248+
249+ if ( this . fileHelper . Exists ( testHostExeNugetPath ) )
250+ {
251+ EqtTrace . Verbose ( "DotnetTestHostManager: Testhost.exe/testhost.x86.exe found at path: " + testHostExeNugetPath ) ;
252+ startInfo . FileName = testHostExeNugetPath ;
253+ testHostExeFound = true ;
254+ }
255+ }
256+ }
212257 }
213- else
258+
259+ if ( ! testHostExeFound )
214260 {
215261 var currentProcessPath = this . processHelper . GetCurrentProcessFileName ( ) ;
216262
@@ -227,9 +273,6 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
227273 startInfo . FileName = this . dotnetHostHelper . GetDotnetPath ( ) ;
228274 }
229275
230- var runtimeConfigDevPath = Path . Combine ( sourceDirectory , string . Concat ( sourceFile , ".runtimeconfig.dev.json" ) ) ;
231- var testHostPath = this . GetTestHostPath ( runtimeConfigDevPath , depsFilePath , sourceDirectory ) ;
232-
233276 EqtTrace . Verbose ( "DotnetTestHostmanager: Full path of testhost.dll is {0}" , testHostPath ) ;
234277 args = "exec" + args ;
235278 args += " " + testHostPath . AddDoubleQuote ( ) ;
@@ -394,6 +437,7 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath,
394437
395438 testHostPath = Path . Combine ( testhostPackage . Path , testHostPath ) ;
396439 this . hostPackageVersion = testhostPackage . Version ;
440+ this . IsVersionCheckRequired = ! this . hostPackageVersion . StartsWith ( "15.0.0" ) ;
397441 EqtTrace . Verbose ( "DotnetTestHostmanager: Relative path of testhost.dll with respect to package folder is {0}" , testHostPath ) ;
398442 }
399443 }
0 commit comments