@@ -207,21 +207,76 @@ public void ItRestoresWithRidSpecificOptions(params string[] ridOptions)
207207 var assetsFilePath = Path . Combine ( rootPath , "obj" , "project.assets.json" ) ;
208208 File . Exists ( assetsFilePath ) . Should ( ) . BeTrue ( ) ;
209209
210- // Verify that the assets file contains RID-specific targets when using RID options
211- if ( ridOptions . Contains ( "-r" ) || ridOptions . Contains ( "--runtime" ) ||
212- ridOptions . Contains ( "--os" ) || ridOptions . Contains ( "-a" ) || ridOptions . Contains ( "--arch" ) )
210+ // Verify that the assets file contains the expected RID-specific target
211+ var assetsContents = JObject . Parse ( File . ReadAllText ( assetsFilePath ) ) ;
212+ var targets = assetsContents [ "targets" ] ;
213+ targets . Should ( ) . NotBeNull ( "assets file should contain targets section" ) ;
214+
215+ // Determine the expected RID based on the options provided
216+ string expectedRid = GetExpectedRid ( ridOptions ) ;
217+ string expectedTarget = $ "{ ToolsetInfo . CurrentTargetFramework } /{ expectedRid } ";
218+
219+ // Check that the specific target exists
220+ var specificTarget = targets [ expectedTarget ] ;
221+ specificTarget . Should ( ) . NotBeNull ( $ "assets file should contain target '{ expectedTarget } ' when using RID options: { string . Join ( " " , ridOptions ) } ") ;
222+ }
223+
224+ private static string GetExpectedRid ( string [ ] ridOptions )
225+ {
226+ // Check if explicit runtime is provided
227+ for ( int i = 0 ; i < ridOptions . Length ; i ++ )
228+ {
229+ if ( ( ridOptions [ i ] == "-r" || ridOptions [ i ] == "--runtime" ) && i + 1 < ridOptions . Length )
230+ {
231+ return ridOptions [ i + 1 ] ;
232+ }
233+ }
234+
235+ // Get current platform defaults
236+ string currentOs = GetCurrentOsPart ( ) ;
237+ string currentArch = GetCurrentArchPart ( ) ;
238+
239+ // Check for --os and --arch options to synthesize RID
240+ string targetOs = currentOs ;
241+ string targetArch = currentArch ;
242+
243+ for ( int i = 0 ; i < ridOptions . Length ; i ++ )
213244 {
214- var assetsContents = JObject . Parse ( File . ReadAllText ( assetsFilePath ) ) ;
215- var targets = assetsContents [ "targets" ] ;
216- targets . Should ( ) . NotBeNull ( "assets file should contain targets section" ) ;
217-
218- // Check for RID-specific targets (targets with RID have names containing "/")
219- var ridSpecificTargets = targets . Children < JProperty > ( )
220- . Where ( target => target . Name . Contains ( "/" ) )
221- . ToList ( ) ;
222-
223- ridSpecificTargets . Should ( ) . NotBeEmpty ( "assets file should contain RID-specific targets when using RID options" ) ;
245+ if ( ridOptions [ i ] == "--os" && i + 1 < ridOptions . Length )
246+ {
247+ targetOs = ridOptions [ i + 1 ] ;
248+ }
249+ else if ( ( ridOptions [ i ] == "-a" || ridOptions [ i ] == "--arch" ) && i + 1 < ridOptions . Length )
250+ {
251+ targetArch = ridOptions [ i + 1 ] ;
252+ }
224253 }
254+
255+ return $ "{ targetOs } -{ targetArch } ";
256+ }
257+
258+ private static string GetCurrentOsPart ( )
259+ {
260+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
261+ return "win" ;
262+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
263+ return "linux" ;
264+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
265+ return "osx" ;
266+ else
267+ throw new PlatformNotSupportedException ( "Unsupported platform for RID determination" ) ;
268+ }
269+
270+ private static string GetCurrentArchPart ( )
271+ {
272+ return RuntimeInformation . OSArchitecture switch
273+ {
274+ Architecture . X64 => "x64" ,
275+ Architecture . X86 => "x86" ,
276+ Architecture . Arm64 => "arm64" ,
277+ Architecture . Arm => "arm" ,
278+ _ => throw new PlatformNotSupportedException ( $ "Unsupported architecture: { RuntimeInformation . OSArchitecture } ")
279+ } ;
225280 }
226281
227282 private static string [ ] HandleStaticGraphEvaluation ( bool useStaticGraphEvaluation , string [ ] args ) =>
0 commit comments