22using BenchmarkDotNet . Detectors ;
33using BenchmarkDotNet . Environments ;
44using BenchmarkDotNet . Extensions ;
5- using BenchmarkDotNet . Helpers ;
65using BenchmarkDotNet . Jobs ;
76using BenchmarkDotNet . Portability ;
87using BenchmarkDotNet . Running ;
@@ -25,7 +24,8 @@ internal static IToolchain GetToolchain(this BenchmarkCase benchmarkCase)
2524 : GetToolchain (
2625 benchmarkCase . GetRuntime ( ) ,
2726 benchmarkCase . Descriptor ,
28- benchmarkCase . Job . HasDynamicBuildCharacteristic ( )
27+ benchmarkCase . Job . HasDynamicBuildCharacteristic ( ) ,
28+ benchmarkCase . Job . Environment . HasValue ( EnvironmentMode . RuntimeCharacteristic )
2929 ) ;
3030
3131 internal static IToolchain GetToolchain ( this Job job )
@@ -34,20 +34,26 @@ internal static IToolchain GetToolchain(this Job job)
3434 : GetToolchain (
3535 job . ResolveValue ( EnvironmentMode . RuntimeCharacteristic , EnvironmentResolver . Instance ) ,
3636 null ,
37- job . HasDynamicBuildCharacteristic ( )
37+ job . HasDynamicBuildCharacteristic ( ) ,
38+ job . Environment . HasValue ( EnvironmentMode . RuntimeCharacteristic )
3839 ) ;
3940
40- internal static IToolchain GetToolchain ( this Runtime runtime , Descriptor ? descriptor = null , bool preferMsBuildToolchains = false )
41+ internal static IToolchain GetToolchain ( this Runtime runtime , Descriptor ? descriptor = null , bool preferMsBuildToolchains = false , bool isRuntimeExplicit = false )
4142 {
4243 switch ( runtime )
4344 {
4445 case ClrRuntime clrRuntime :
45- if ( ! preferMsBuildToolchains && RuntimeInformation . IsFullFramework
46- && RuntimeInformation . GetCurrentRuntime ( ) . MsBuildMoniker == runtime . MsBuildMoniker )
46+ bool ShouldUseCurrentRuntime ( )
4747 {
48- return RoslynToolchain . Instance ;
48+ var assembly = isRuntimeExplicit
49+ ? descriptor ? . WorkloadMethod . DeclaringType . Assembly
50+ : null ;
51+ return runtime . MsBuildMoniker == ClrRuntime . GetTargetOrCurrentVersion ( assembly ) . MsBuildMoniker ;
4952 }
5053
54+ if ( ! preferMsBuildToolchains && RuntimeInformation . IsFullFramework && ShouldUseCurrentRuntime ( ) )
55+ return RoslynToolchain . Instance ;
56+
5157 return clrRuntime . RuntimeMoniker != RuntimeMoniker . NotRecognized
5258 ? GetToolchain ( clrRuntime . RuntimeMoniker )
5359 : CsProjClassicNetToolchain . From ( clrRuntime . MsBuildMoniker ) ;
0 commit comments