@@ -67,6 +67,8 @@ public class DotnetTestHostManager : ITestRuntimeProvider
67
67
68
68
private Architecture architecture ;
69
69
70
+ private bool isVersionCheckRequired = true ;
71
+
70
72
/// <summary>
71
73
/// Initializes a new instance of the <see cref="DotnetTestHostManager"/> class.
72
74
/// </summary>
@@ -111,8 +113,20 @@ internal DotnetTestHostManager(
111
113
112
114
/// <summary>
113
115
/// 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;
114
117
/// </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
+ }
116
130
117
131
/// <summary>
118
132
/// Gets a value indicating whether the test host supports protocol version check
@@ -203,14 +217,46 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
203
217
EqtTrace . Verbose ( "DotnetTestHostmanager: File {0}, doesnot exist" , depsFilePath ) ;
204
218
}
205
219
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 ) )
210
226
{
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
+ }
212
257
}
213
- else
258
+
259
+ if ( ! testHostExeFound )
214
260
{
215
261
var currentProcessPath = this . processHelper . GetCurrentProcessFileName ( ) ;
216
262
@@ -227,9 +273,6 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
227
273
startInfo . FileName = this . dotnetHostHelper . GetDotnetPath ( ) ;
228
274
}
229
275
230
- var runtimeConfigDevPath = Path . Combine ( sourceDirectory , string . Concat ( sourceFile , ".runtimeconfig.dev.json" ) ) ;
231
- var testHostPath = this . GetTestHostPath ( runtimeConfigDevPath , depsFilePath , sourceDirectory ) ;
232
-
233
276
EqtTrace . Verbose ( "DotnetTestHostmanager: Full path of testhost.dll is {0}" , testHostPath ) ;
234
277
args = "exec" + args ;
235
278
args += " " + testHostPath . AddDoubleQuote ( ) ;
@@ -394,6 +437,7 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath,
394
437
395
438
testHostPath = Path . Combine ( testhostPackage . Path , testHostPath ) ;
396
439
this . hostPackageVersion = testhostPackage . Version ;
440
+ this . IsVersionCheckRequired = ! this . hostPackageVersion . StartsWith ( "15.0.0" ) ;
397
441
EqtTrace . Verbose ( "DotnetTestHostmanager: Relative path of testhost.dll with respect to package folder is {0}" , testHostPath ) ;
398
442
}
399
443
}
0 commit comments