@@ -143,21 +143,14 @@ private bool ValidateCrossgen2Support()
143
143
144
144
bool version5 = crossgen2PackVersion . Major < 6 ;
145
145
bool isSupportedTarget = ExtractTargetPlatformAndArchitecture ( _targetRuntimeIdentifier , out _targetPlatform , out _targetArchitecture ) ;
146
- string targetOS = _targetPlatform switch
147
- {
148
- "linux" => "linux" ,
149
- "linux-musl" => "linux" ,
150
- "osx" => "osx" ,
151
- "win" => "windows" ,
152
- _ => null
153
- } ;
154
146
155
147
// In .NET 5 Crossgen2 supported only the following host->target compilation scenarios:
156
148
// win-x64 -> win-x64
157
149
// linux-x64 -> linux-x64
158
150
// linux-musl-x64 -> linux-musl-x64
151
+ string targetOS = null ;
159
152
isSupportedTarget = isSupportedTarget &&
160
- targetOS != null &&
153
+ GetCrossgen2TargetOS ( out targetOS ) &&
161
154
( ! version5 || _targetRuntimeIdentifier == _hostRuntimeIdentifier ) &&
162
155
GetCrossgen2ComponentsPaths ( version5 ) ;
163
156
@@ -188,6 +181,48 @@ private bool ValidateCrossgen2Support()
188
181
return true ;
189
182
}
190
183
184
+ private bool GetCrossgen2TargetOS ( out string targetOS )
185
+ {
186
+ targetOS = null ;
187
+
188
+ // Determine targetOS based on target rid.
189
+ // Use the runtime graph to support non-portable target rids.
190
+ var runtimeGraph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
191
+ string portablePlatform = NuGetUtils . GetBestMatchingRid (
192
+ runtimeGraph ,
193
+ _targetPlatform ,
194
+ new [ ] { "linux" , "linux-musl" , "osx" , "win" } ,
195
+ out _ ) ;
196
+
197
+ // For source-build, allow the bootstrap SDK rid to be unknown to the runtime repo graph.
198
+ if ( portablePlatform == null && _targetRuntimeIdentifier == _hostRuntimeIdentifier )
199
+ {
200
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
201
+ {
202
+ portablePlatform = "linux" ;
203
+ }
204
+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
205
+ {
206
+ portablePlatform = "win" ;
207
+ }
208
+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
209
+ {
210
+ portablePlatform = "osx" ;
211
+ }
212
+ }
213
+
214
+ targetOS = portablePlatform switch
215
+ {
216
+ "linux" => "linux" ,
217
+ "linux-musl" => "linux" ,
218
+ "osx" => "osx" ,
219
+ "win" => "windows" ,
220
+ _ => null
221
+ } ;
222
+
223
+ return targetOS != null ;
224
+ }
225
+
191
226
private ITaskItem GetNETCoreAppRuntimePack ( )
192
227
{
193
228
return GetNETCoreAppPack ( RuntimePacks , MetadataKeys . FrameworkName ) ;
0 commit comments