44using Microsoft . Build . Framework ;
55using NuGet . RuntimeModel ;
66
7- namespace Microsoft . NET . Build . Tasks
7+ namespace Microsoft . NET . Build . Tasks ;
8+
9+ /// <summary>
10+ /// This task uses the given RID graph in a given SDK to pick the best match from among a set of supported RIDs for the current RID
11+ /// </summary>
12+ public sealed class PickBestRid : TaskBase
813{
914 /// <summary>
10- /// This task uses the given RID graph in a given SDK to pick the best match from among a set of supported RIDs for the current RID
15+ /// The path to the RID graph to read
16+ /// </summary>
17+ [ Required ]
18+ public string RuntimeGraphPath { get ; set ; } = "" ;
19+
20+ /// <summary>
21+ /// The RID to find the best fit for
22+ /// </summary>
23+ [ Required ]
24+ public string TargetRid { get ; set ; } = "" ;
25+
26+ /// <summary>
27+ /// All of the RIDs that are allowed to match against the <see cref="TargetRid"/>
28+ /// </summary>
29+ [ Required ]
30+ public string [ ] SupportedRids { get ; set ; } = Array . Empty < string > ( ) ;
31+
32+ /// <summary>
33+ /// The RID from among <see cref="SupportedRids"/> that best matches the <see cref="TargetRid"/>, if any.
1134 /// </summary>
12- public sealed class PickBestRid : TaskBase
35+ [ Output ]
36+ public string ? MatchingRid { get ; set ; }
37+
38+ protected override void ExecuteCore ( )
1339 {
14- /// <summary>
15- /// The path to the RID graph to read
16- /// </summary>
17- [ Required ]
18- public string RuntimeGraphPath { get ; set ; } = "" ;
19-
20- /// <summary>
21- /// The RID to find the best fit for
22- /// </summary>
23- [ Required ]
24- public string TargetRid { get ; set ; } = "" ;
25-
26- /// <summary>
27- /// All of the RIDs that are allowed to match against the Target RID
28- /// </summary>
29- [ Required ]
30- public string [ ] SupportedRids { get ; set ; } = Array . Empty < string > ( ) ;
31-
32- /// <summary>
33- /// The solution to the puzzle
34- /// </summary>
35- [ Output ]
36- public string ? MatchingRid { get ; set ; }
37-
38- /// <summary>
39- /// Finds the best matching RID from the supported RIDs using the runtime graph.
40- /// </summary>
41- protected override void ExecuteCore ( )
40+ if ( ! File . Exists ( RuntimeGraphPath ) )
41+ {
42+ Log . LogError ( Strings . RuntimeGraphFileDoesNotExist , RuntimeGraphPath ) ;
43+ return ;
44+ }
45+
46+ RuntimeGraph graph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
47+ var bestRidForPlatform = NuGetUtils . GetBestMatchingRid ( graph , TargetRid , SupportedRids , out bool wasInGraph ) ;
48+
49+ if ( ! wasInGraph || bestRidForPlatform == null )
4250 {
43- if ( ! File . Exists ( RuntimeGraphPath ) )
44- {
45- Log . LogError ( Strings . RuntimeGraphFileDoesNotExist , RuntimeGraphPath ) ;
46- return ;
47- }
48-
49- RuntimeGraph graph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
50- string bestRidForPlatform = NuGetUtils . GetBestMatchingRid ( graph , TargetRid , SupportedRids , out bool wasInGraph ) ;
51-
52- if ( ! wasInGraph || bestRidForPlatform == null )
53- {
54- Log . LogError ( Strings . UnableToFindMatchingRid , TargetRid , string . Join ( "," , SupportedRids ) , RuntimeGraphPath ) ;
55- return ;
56- }
57-
58- MatchingRid = bestRidForPlatform ;
51+ Log . LogError ( Strings . UnableToFindMatchingRid , TargetRid , string . Join ( "," , SupportedRids ) , RuntimeGraphPath ) ;
52+ return ;
5953 }
54+
55+ MatchingRid = bestRidForPlatform ;
6056 }
61- }
57+ }
0 commit comments