@@ -44,7 +44,7 @@ public void AssertAllResolverErrorsLoggedWhenSdkNotResolved()
4444
4545 SdkReference sdk = new SdkReference ( "notfound" , "referencedVersion" , "minimumVersion" ) ;
4646
47- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
47+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
4848
4949 result . Success . ShouldBeFalse ( ) ;
5050 result . ShouldNotBeNull ( ) ;
@@ -77,7 +77,7 @@ public void AssertResolutionWarnsIfResolvedVersionIsDifferentFromReferencedVersi
7777 ) )
7878 } ) ;
7979
80- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
80+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
8181
8282 result . Path . ShouldBe ( "path" ) ;
8383
@@ -92,7 +92,7 @@ public void AssertErrorLoggedWhenResolverThrows()
9292
9393 SdkReference sdk = new SdkReference ( "1sdkName" , "version1" , "minimumVersion" ) ;
9494
95- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
95+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
9696
9797 result . Path . ShouldBe ( "resolverpath1" ) ;
9898 _logger . Warnings . Select ( i => i . Message ) . ShouldBe ( new [ ] { "The SDK resolver \" MockSdkResolverThrows\" failed to run. EXMESSAGE" } ) ;
@@ -105,7 +105,7 @@ public void AssertFirstResolverCanResolve()
105105
106106 SdkReference sdk = new SdkReference ( "1sdkName" , "referencedVersion" , "minimumVersion" ) ;
107107
108- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
108+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
109109
110110 result . Path . ShouldBe ( "resolverpath1" ) ;
111111 _logger . BuildMessageEvents . Select ( i => i . Message ) . ShouldContain ( "MockSdkResolver1 running" ) ;
@@ -120,7 +120,7 @@ public void AssertFirstResolverErrorsSupressedWhenResolved()
120120 // be logged because MockSdkResolver2 will succeed.
121121 SdkReference sdk = new SdkReference ( "2sdkName" , "version2" , "minimumVersion" ) ;
122122
123- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
123+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
124124
125125 result . Path . ShouldBe ( "resolverpath2" ) ;
126126
@@ -143,10 +143,10 @@ public void AssertResolverHasStatePreserved()
143143 SdkReference sdk = new SdkReference ( "othersdk" , "1.0" , "minimumVersion" ) ;
144144
145145 // First call should not know state
146- SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) . Path . ShouldBe ( "resolverpath" ) ;
146+ SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) . Path . ShouldBe ( "resolverpath" ) ;
147147
148148 // Second call should have received state
149- SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) . Path . ShouldBe ( MockSdkResolverWithState . Expected ) ;
149+ SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) . Path . ShouldBe ( MockSdkResolverWithState . Expected ) ;
150150 }
151151
152152 [ Fact ]
@@ -159,10 +159,10 @@ public void AssertResolverStateNotPreserved()
159159 SdkReference sdk = new SdkReference ( "othersdk" , "1.0" , "minimumVersion" ) ;
160160
161161 // First call should not know state
162- SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) . Path . ShouldBe ( "resolverpath" ) ;
162+ SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) . Path . ShouldBe ( "resolverpath" ) ;
163163
164164 // Second call should have received state
165- SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) . Path . ShouldBe ( "resolverpath" ) ;
165+ SdkResolverService . Instance . ResolveSdk ( submissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) . Path . ShouldBe ( "resolverpath" ) ;
166166 }
167167
168168 [ Theory ]
@@ -203,13 +203,13 @@ public void CachingWrapperShouldWarnWhenMultipleVersionsAreReferenced()
203203 resolver
204204 } ) ;
205205
206- var result = service . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
206+ var result = service . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
207207 resolver . ResolvedCalls . Count . ShouldBe ( 1 ) ;
208208 result . Path . ShouldBe ( "path" ) ;
209209 result . Version . ShouldBe ( "1.0.0" ) ;
210210 _logger . WarningCount . ShouldBe ( 0 ) ;
211211
212- result = service . ResolveSdk ( BuildEventContext . InvalidSubmissionId , new SdkReference ( "foo" , "2.0.0" , null ) , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
212+ result = service . ResolveSdk ( BuildEventContext . InvalidSubmissionId , new SdkReference ( "foo" , "2.0.0" , null ) , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
213213 resolver . ResolvedCalls . Count . ShouldBe ( 1 ) ;
214214 result . Path . ShouldBe ( "path" ) ;
215215 result . Version . ShouldBe ( "1.0.0" ) ;
@@ -285,7 +285,7 @@ public void SdkResolverCanReturnNoPaths(bool includePropertiesAndItems)
285285
286286 SdkResolverService . Instance . InitializeForTests ( null , new List < SdkResolver > ( ) { resolver } ) ;
287287
288- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
288+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
289289
290290 result . Success . ShouldBeTrue ( ) ;
291291 result . Path . ShouldBeNull ( ) ;
@@ -322,7 +322,7 @@ public void SdkResultCanReturnPropertiesAndItems()
322322
323323 SdkResolverService . Instance . InitializeForTests ( null , new List < SdkResolver > ( ) { resolver } ) ;
324324
325- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
325+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
326326
327327 result . Success . ShouldBeTrue ( ) ;
328328 result . Path . ShouldBe ( expectedPath ) ;
@@ -369,7 +369,7 @@ public void SdkResultCanReturnMultiplePaths(bool includePropertiesAndItems)
369369
370370 SdkResolverService . Instance . InitializeForTests ( null , new List < SdkResolver > ( ) { resolver } ) ;
371371
372- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
372+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
373373
374374 result . Success . ShouldBeTrue ( ) ;
375375
@@ -417,7 +417,7 @@ public void AssertResolutionWarnsIfResolvedVersionIsDifferentFromReferencedVersi
417417
418418 SdkResolverService . Instance . InitializeForTests ( null , new List < SdkResolver > ( ) { resolver } ) ;
419419
420- var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ;
420+ var result = SdkResolverService . Instance . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ;
421421
422422 result . Success . ShouldBeTrue ( ) ;
423423
@@ -465,7 +465,7 @@ public void CachingWrapperShouldOnlyResolveOnce()
465465 Parallel . For (
466466 0 ,
467467 10 ,
468- _ => service . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false ) ) ;
468+ _ => service . ResolveSdk ( BuildEventContext . InvalidSubmissionId , sdk , _loggingContext , new MockElementLocation ( "file" ) , "sln" , "projectPath" , interactive : false , isRunningInVisualStudio : false ) ) ;
469469
470470 var result = resolver . ResolvedCalls . ShouldHaveSingleItem ( ) ;
471471
@@ -502,11 +502,42 @@ public void InteractiveIsSetForResolverContext()
502502 "sln" ,
503503 "projectPath" ,
504504 // Pass along interactive and expect it to be received in the SdkResolverContext
505- interactive : true ) ;
505+ interactive : true ,
506+ false ) ;
506507
507508 interactive . ShouldBeTrue ( ) ;
508509 }
509510
511+ [ Fact ]
512+ public void IsRunningInVisualStudioIsSetForResolverContext ( )
513+ {
514+ bool isRunningInVisualStudio = false ;
515+
516+ var service = new CachingSdkResolverService ( ) ;
517+ service . InitializeForTests (
518+ resolvers : new List < SdkResolver >
519+ {
520+ new SdkUtilities . ConfigurableMockSdkResolver ( ( sdkRference , resolverContext , factory ) =>
521+ {
522+ isRunningInVisualStudio = resolverContext . IsRunningInVisualStudio ;
523+ return null ;
524+ } )
525+ } ) ;
526+
527+ var result = service . ResolveSdk (
528+ BuildEventContext . InvalidSubmissionId ,
529+ new SdkReference ( "foo" , "1.0.0" , null ) ,
530+ _loggingContext ,
531+ new MockElementLocation ( "file" ) ,
532+ "sln" ,
533+ "projectPath" ,
534+ false ,
535+ // Pass along isRunningInVisualStudio and expect it to be received in the SdkResolverContext
536+ isRunningInVisualStudio : true ) ;
537+
538+ isRunningInVisualStudio . ShouldBeTrue ( ) ;
539+ }
540+
510541 private class MockLoaderStrategy : SdkResolverLoader
511542 {
512543 private readonly bool _includeErrorResolver ;
0 commit comments