@@ -52,21 +52,7 @@ protected override void ExecuteCore()
52
52
_runtimePack = GetNETCoreAppRuntimePack ( ) ;
53
53
_targetRuntimeIdentifier = _runtimePack ? . GetMetadata ( MetadataKeys . RuntimeIdentifier ) ;
54
54
55
- // Get the list of runtime identifiers that we support and can target
56
- ITaskItem targetingPack = GetNETCoreAppTargetingPack ( ) ;
57
- string supportedRuntimeIdentifiers = targetingPack ? . GetMetadata ( MetadataKeys . RuntimePackRuntimeIdentifiers ) ;
58
-
59
- var runtimeGraph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
60
- var supportedRIDsList = supportedRuntimeIdentifiers == null ? Array . Empty < string > ( ) : supportedRuntimeIdentifiers . Split ( ';' ) ;
61
-
62
- // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
63
- _hostRuntimeIdentifier = NuGetUtils . GetBestMatchingRid (
64
- runtimeGraph ,
65
- NETCoreSdkRuntimeIdentifier ,
66
- supportedRIDsList ,
67
- out _ ) ;
68
-
69
- if ( _hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null )
55
+ if ( _targetRuntimeIdentifier == null )
70
56
{
71
57
Log . LogError ( Strings . ReadyToRunNoValidRuntimePackageError ) ;
72
58
return ;
@@ -96,6 +82,13 @@ protected override void ExecuteCore()
96
82
97
83
private bool ValidateCrossgenSupport ( )
98
84
{
85
+ _hostRuntimeIdentifier = GetHostRuntimeIdentifierForCrossgen ( ) ;
86
+ if ( _hostRuntimeIdentifier == null )
87
+ {
88
+ Log . LogError ( Strings . ReadyToRunNoValidRuntimePackageError ) ;
89
+ return false ;
90
+ }
91
+
99
92
_crossgenTool . PackagePath = _runtimePack ? . GetMetadata ( MetadataKeys . PackageDirectory ) ;
100
93
if ( _crossgenTool . PackagePath == null )
101
94
{
@@ -121,12 +114,39 @@ private bool ValidateCrossgenSupport()
121
114
}
122
115
123
116
return true ;
117
+
118
+ string GetHostRuntimeIdentifierForCrossgen ( )
119
+ {
120
+ // Crossgen's host RID comes from the runtime pack that Crossgen will be loaded from.
121
+
122
+ // Get the list of runtime identifiers that we support and can target
123
+ ITaskItem targetingPack = GetNETCoreAppTargetingPack ( ) ;
124
+ string supportedRuntimeIdentifiers = targetingPack ? . GetMetadata ( MetadataKeys . RuntimePackRuntimeIdentifiers ) ;
125
+
126
+ var runtimeGraph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
127
+ var supportedRIDsList = supportedRuntimeIdentifiers == null ? Array . Empty < string > ( ) : supportedRuntimeIdentifiers . Split ( ';' ) ;
128
+
129
+ // Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
130
+ return NuGetUtils . GetBestMatchingRid (
131
+ runtimeGraph ,
132
+ NETCoreSdkRuntimeIdentifier ,
133
+ supportedRIDsList ,
134
+ out _ ) ;
135
+ }
124
136
}
125
137
126
138
private bool ValidateCrossgen2Support ( )
127
139
{
128
140
ITaskItem crossgen2Pack = Crossgen2Packs ? . FirstOrDefault ( ) ;
129
- _crossgen2Tool . PackagePath = crossgen2Pack ? . GetMetadata ( MetadataKeys . PackageDirectory ) ;
141
+
142
+ _hostRuntimeIdentifier = crossgen2Pack ? . GetMetadata ( MetadataKeys . RuntimeIdentifier ) ;
143
+ if ( _hostRuntimeIdentifier == null )
144
+ {
145
+ Log . LogError ( Strings . ReadyToRunNoValidRuntimePackageError ) ;
146
+ return false ;
147
+ }
148
+
149
+ _crossgen2Tool . PackagePath = crossgen2Pack . GetMetadata ( MetadataKeys . PackageDirectory ) ;
130
150
131
151
if ( string . IsNullOrEmpty ( _crossgen2Tool . PackagePath ) ||
132
152
! NuGetVersion . TryParse ( crossgen2Pack . GetMetadata ( MetadataKeys . NuGetPackageVersion ) , out NuGetVersion crossgen2PackVersion ) )
@@ -181,42 +201,19 @@ private bool GetCrossgen2TargetOS(out string targetOS)
181
201
182
202
// Determine targetOS based on target rid.
183
203
// Use the runtime graph to support non-portable target rids.
204
+ // Use the full target rid instead of just the target OS as the runtime graph
205
+ // may only have the full target rid and not an OS-only rid for non-portable target rids
206
+ // added by our source-build partners.
184
207
var runtimeGraph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
185
208
string portablePlatform = NuGetUtils . GetBestMatchingRid (
186
209
runtimeGraph ,
187
- _targetPlatform ,
188
- new [ ] { "linux" , "linux-musl" , " osx", "win" , "freebsd" , "illumos" } ,
210
+ _targetRuntimeIdentifier ,
211
+ new [ ] { "linux" , "osx" , "win" , "freebsd" , "illumos" } ,
189
212
out _ ) ;
190
213
191
- // For source-build, allow the bootstrap SDK rid to be unknown to the runtime repo graph.
192
- if ( portablePlatform == null && _targetRuntimeIdentifier == _hostRuntimeIdentifier )
193
- {
194
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
195
- {
196
- portablePlatform = "win" ;
197
- }
198
- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
199
- {
200
- portablePlatform = "linux" ;
201
- }
202
- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "FREEBSD" ) ) )
203
- {
204
- portablePlatform = "freebsd" ;
205
- }
206
- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "ILLUMOS" ) ) )
207
- {
208
- portablePlatform = "illumos" ;
209
- }
210
- else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
211
- {
212
- portablePlatform = "osx" ;
213
- }
214
- }
215
-
216
214
targetOS = portablePlatform switch
217
215
{
218
216
"linux" => "linux" ,
219
- "linux-musl" => "linux" ,
220
217
"osx" => "osx" ,
221
218
"win" => "windows" ,
222
219
"freebsd" => "freebsd" ,
0 commit comments