2
2
* Licensed to the .NET Foundation under one or more agreements.
3
3
* The .NET Foundation licenses this file to you under the MIT license.
4
4
*--------------------------------------------------------------------------------------------*/
5
- import { DotnetVersionSpecRequirement } from '../DotnetVersionSpecRequirement' ;
6
5
import { IDotnetFindPathContext } from '../IDotnetFindPathContext' ;
7
6
import { CommandExecutor } from '../Utils/CommandExecutor' ;
8
7
import { ICommandExecutor } from '../Utils/ICommandExecutor' ;
@@ -26,14 +25,12 @@ export class DotnetConditionValidator implements IDotnetConditionValidator
26
25
public async dotnetMeetsRequirement ( dotnetExecutablePath : string , requirement : IDotnetFindPathContext ) : Promise < boolean >
27
26
{
28
27
const availableRuntimes = await this . getRuntimes ( dotnetExecutablePath ) ;
29
- const requestedMajorMinor = versionUtils . getMajorMinor ( requirement . acquireContext . version , this . workerContext . eventStream , this . workerContext ) ;
30
28
const hostArch = await this . getHostArchitecture ( dotnetExecutablePath , requirement ) ;
31
29
32
30
if ( availableRuntimes . some ( ( runtime ) =>
33
31
{
34
- const availableVersion = versionUtils . getMajorMinor ( runtime . version , this . workerContext . eventStream , this . workerContext ) ;
35
32
return runtime . mode === requirement . acquireContext . mode && this . stringArchitectureMeetsRequirement ( hostArch , requirement . acquireContext . architecture ) &&
36
- this . stringVersionMeetsRequirement ( availableVersion , requestedMajorMinor , requirement . versionSpecRequirement ) ;
33
+ this . stringVersionMeetsRequirement ( runtime . version , requirement . acquireContext . version , requirement ) ;
37
34
} ) )
38
35
{
39
36
return true ;
@@ -44,16 +41,15 @@ export class DotnetConditionValidator implements IDotnetConditionValidator
44
41
if ( availableSDKs . some ( ( sdk ) =>
45
42
{
46
43
// The SDK includes the Runtime, ASP.NET Core Runtime, and Windows Desktop Runtime. So, we don't need to check the mode.
47
- const availableVersion = versionUtils . getMajorMinor ( sdk . version , this . workerContext . eventStream , this . workerContext ) ;
48
- return this . stringArchitectureMeetsRequirement ( hostArch , requirement . acquireContext . architecture ) && this . stringVersionMeetsRequirement ( availableVersion , requestedMajorMinor , requirement . versionSpecRequirement ) ;
44
+ return this . stringArchitectureMeetsRequirement ( hostArch , requirement . acquireContext . architecture ) && this . stringVersionMeetsRequirement ( sdk . version , requirement . acquireContext . version , requirement ) ;
49
45
} ) )
50
46
{
51
47
return true ;
52
48
}
53
49
else
54
50
{
55
51
this . workerContext . eventStream . post ( new DotnetFindPathDidNotMeetCondition ( `${ dotnetExecutablePath } did NOT satisfy the conditions: hostArch: ${ hostArch } , requiredArch: ${ requirement . acquireContext . architecture } ,
56
- required version: ${ requestedMajorMinor } ` ) ) ;
52
+ required version: ${ requirement . acquireContext . version } , required mode: ${ requirement . acquireContext . mode } ` ) ) ;
57
53
}
58
54
}
59
55
@@ -136,29 +132,51 @@ Please set the PATH to a dotnet host that matches the architecture ${requirement
136
132
return os . platform ( ) === 'win32' ? ( await this . executor ! . tryFindWorkingCommand ( [ CommandExecutor . makeCommand ( 'chcp' , [ '65001' ] ) ] ) ) !== null : false ;
137
133
}
138
134
139
- private stringVersionMeetsRequirement ( availableVersion : string , requestedVersion : string , requirement : DotnetVersionSpecRequirement ) : boolean
135
+ private stringVersionMeetsRequirement ( availableVersion : string , requestedVersion : string , requirement : IDotnetFindPathContext ) : boolean
140
136
{
141
137
const availableMajor = Number ( versionUtils . getMajor ( availableVersion , this . workerContext . eventStream , this . workerContext ) ) ;
142
138
const requestedMajor = Number ( versionUtils . getMajor ( requestedVersion , this . workerContext . eventStream , this . workerContext ) ) ;
139
+ const requestedPatchStr : string | null = requirement . acquireContext . mode !== 'sdk' ? versionUtils . getRuntimePatchVersionString ( requestedVersion , this . workerContext . eventStream , this . workerContext )
140
+ : versionUtils . getSDKCompleteBandAndPatchVersionString ( requestedVersion , this . workerContext . eventStream , this . workerContext ) ;
141
+ const requestedPatch = requestedPatchStr ? Number ( requestedPatchStr ) : null ;
143
142
144
143
if ( availableMajor === requestedMajor )
145
144
{
146
145
const availableMinor = Number ( versionUtils . getMinor ( availableVersion , this . workerContext . eventStream , this . workerContext ) ) ;
147
146
const requestedMinor = Number ( versionUtils . getMinor ( requestedVersion , this . workerContext . eventStream , this . workerContext ) ) ;
148
147
149
- switch ( requirement )
148
+ if ( availableMinor === requestedMinor && requestedPatch )
150
149
{
151
- case 'equal' :
152
- return availableMinor === requestedMinor ;
153
- case 'greater_than_or_equal' :
154
- return availableMinor >= requestedMinor ;
155
- case 'less_than_or_equal' :
156
- return availableMinor <= requestedMinor ;
150
+ const availablePatchStr : string | null = requirement . acquireContext . mode !== 'sdk' ? versionUtils . getRuntimePatchVersionString ( availableVersion , this . workerContext . eventStream , this . workerContext )
151
+ : versionUtils . getSDKCompleteBandAndPatchVersionString ( availableVersion , this . workerContext . eventStream , this . workerContext ) ;
152
+ const availablePatch = availablePatchStr ? Number ( availablePatchStr ) : null ;
153
+ switch ( requirement . versionSpecRequirement )
154
+ {
155
+ case 'equal' :
156
+ return availablePatch === requestedPatch ;
157
+ case 'greater_than_or_equal' :
158
+ // the 'availablePatch' must exist, since the version is from --list-runtimes or --list-sdks.
159
+ return availablePatch ! >= requestedPatch ;
160
+ case 'less_than_or_equal' :
161
+ return availablePatch ! <= requestedPatch ;
162
+ }
163
+ }
164
+ else
165
+ {
166
+ switch ( requirement . versionSpecRequirement )
167
+ {
168
+ case 'equal' :
169
+ return availableMinor === requestedMinor ;
170
+ case 'greater_than_or_equal' :
171
+ return availableMinor >= requestedMinor ;
172
+ case 'less_than_or_equal' :
173
+ return availableMinor <= requestedMinor ;
174
+ }
157
175
}
158
176
}
159
177
else
160
178
{
161
- switch ( requirement )
179
+ switch ( requirement . versionSpecRequirement )
162
180
{
163
181
case 'equal' :
164
182
return false ;
0 commit comments