@@ -223,6 +223,94 @@ public void PackagesFrameworkDependentRidSpecificPackagesCorrectly()
223
223
foundRids . Should ( ) . BeEquivalentTo ( expectedRids , "The top-level package should declare all of the RIDs for the tools it contains" ) ;
224
224
}
225
225
226
+ [ Fact ]
227
+ public void PackageToolWithAnyRid ( )
228
+ {
229
+ var toolSettings = new TestToolBuilder . TestToolSettings ( )
230
+ {
231
+ RidSpecific = true ,
232
+ IncludeAnyRid = true
233
+ } ;
234
+
235
+ string toolPackagesPath = ToolBuilder . CreateTestTool ( Log , toolSettings ) ;
236
+
237
+ var packages = Directory . GetFiles ( toolPackagesPath , "*.nupkg" ) ;
238
+ var packageIdentifier = toolSettings . ToolPackageId ;
239
+ var expectedRids = ToolsetInfo . LatestRuntimeIdentifiers . Split ( ';' ) ;
240
+
241
+ packages . Length . Should ( ) . Be ( expectedRids . Length + 1 + 1 , "There should be one package for the tool-wrapper, one for the top-level manifest, and one for each RID" ) ;
242
+ foreach ( string rid in expectedRids )
243
+ {
244
+ var packageName = $ "{ toolSettings . ToolPackageId } .{ rid } .{ toolSettings . ToolPackageVersion } ";
245
+ var package = packages . FirstOrDefault ( p => p . EndsWith ( packageName + ".nupkg" ) ) ;
246
+ package . Should ( ) . NotBeNull ( $ "Package { packageName } should be present in the tool packages directory")
247
+ . And . Satisfy < string > ( EnsurePackageIsAnExecutable ) ;
248
+ }
249
+
250
+ // Ensure that the package with the "any" RID is present
251
+ var anyRidPackage = packages . FirstOrDefault ( p => p . EndsWith ( $ "{ packageIdentifier } .any.{ toolSettings . ToolPackageVersion } .nupkg") ) ;
252
+ anyRidPackage . Should ( ) . NotBeNull ( $ "Package { packageIdentifier } .any.{ toolSettings . ToolPackageVersion } .nupkg should be present in the tool packages directory")
253
+ . And . Satisfy < string > ( EnsurePackageIsFdd ) ;
254
+
255
+ // top-level package should declare all of the rids
256
+ var topLevelPackage = packages . First ( p => p . EndsWith ( $ "{ packageIdentifier } .{ toolSettings . ToolPackageVersion } .nupkg") ) ;
257
+ var settingsXml = GetToolSettingsFile ( topLevelPackage ) ;
258
+ var packageNodes = GetRidsInSettingsFile ( settingsXml ) ;
259
+
260
+ packageNodes . Should ( ) . BeEquivalentTo ( [ .. expectedRids , "any" ] , "The top-level package should declare all of the RIDs for the tools it contains" ) ;
261
+ }
262
+
263
+ [ Fact ]
264
+ public void InstallAndRunToolFromAnyRid ( )
265
+ {
266
+ var toolSettings = new TestToolBuilder . TestToolSettings ( )
267
+ {
268
+ IncludeAnyRid = true // will make one package with the "any" RID
269
+ } ;
270
+ string toolPackagesPath = ToolBuilder . CreateTestTool ( Log , toolSettings ) ;
271
+ var packages = Directory . GetFiles ( toolPackagesPath , "*.nupkg" ) . Select ( p => Path . GetFileName ( p ) ) . ToArray ( ) ;
272
+ packages . Should ( ) . BeEquivalentTo ( [
273
+ $ "{ toolSettings . ToolPackageId } .{ toolSettings . ToolPackageVersion } .nupkg",
274
+ $ "{ toolSettings . ToolPackageId } .any.{ toolSettings . ToolPackageVersion } .nupkg"
275
+ ] , "There should be two packages: one for the tool-wrapper and one for the 'any' RID" ) ;
276
+ var testDirectory = _testAssetsManager . CreateTestDirectory ( ) ;
277
+ var homeFolder = Path . Combine ( testDirectory . Path , "home" ) ;
278
+
279
+ new DotnetToolCommand ( Log , "exec" , toolSettings . ToolPackageId , "--yes" , "--add-source" , toolPackagesPath )
280
+ . WithEnvironmentVariables ( homeFolder )
281
+ . WithWorkingDirectory ( testDirectory . Path )
282
+ . Execute ( )
283
+ . Should ( ) . Pass ( )
284
+ . And . HaveStdOutContaining ( "Hello Tool!" ) ;
285
+ }
286
+
287
+ [ Fact ]
288
+ public void InstallAndRunToolFromAnyRidWhenOtherRidsArePresentButIncompatible ( )
289
+ {
290
+ var toolSettings = new TestToolBuilder . TestToolSettings ( )
291
+ {
292
+ IncludeCurrentRid = false ,
293
+ RidSpecific = true , // will make one package for each RID except the current RID
294
+ IncludeAnyRid = true // will make one package with the "any" RID
295
+ } ;
296
+ List < string > expectedRids = [ .. ToolsetInfo . LatestRuntimeIdentifiers . Split ( ';' ) . Where ( rid => rid != RuntimeInformation . RuntimeIdentifier ) , "any" ] ;
297
+
298
+ string toolPackagesPath = ToolBuilder . CreateTestTool ( Log , toolSettings ) ;
299
+ var packages = Directory . GetFiles ( toolPackagesPath , "*.nupkg" ) . Select ( p => Path . GetFileName ( p ) ) . ToArray ( ) ;
300
+ packages . Should ( ) . BeEquivalentTo ( [
301
+ $ "{ toolSettings . ToolPackageId } .{ toolSettings . ToolPackageVersion } .nupkg",
302
+ .. expectedRids . Select ( rid => $ "{ toolSettings . ToolPackageId } .{ rid } .{ toolSettings . ToolPackageVersion } .nupkg") ,
303
+ ] , $ "There should be { 1 + expectedRids . Count } packages: one for the tool-wrapper and one for each RID except the current RID") ;
304
+ var testDirectory = _testAssetsManager . CreateTestDirectory ( ) ;
305
+ var homeFolder = Path . Combine ( testDirectory . Path , "home" ) ;
306
+
307
+ new DotnetToolCommand ( Log , "exec" , toolSettings . ToolPackageId , "--yes" , "--add-source" , toolPackagesPath )
308
+ . WithEnvironmentVariables ( homeFolder )
309
+ . WithWorkingDirectory ( testDirectory . Path )
310
+ . Execute ( )
311
+ . Should ( ) . Pass ( )
312
+ . And . HaveStdOutContaining ( "Hello Tool!" ) ;
313
+ }
226
314
227
315
private void EnsurePackageIsFdd ( string packagePath )
228
316
{
0 commit comments