6
6
using System . IO ;
7
7
using System . Linq ;
8
8
using System . Runtime . InteropServices ;
9
- using System . Text . RegularExpressions ;
10
9
using Microsoft . Build . Framework ;
11
10
using Microsoft . Build . Utilities ;
12
11
using Newtonsoft . Json ;
@@ -230,58 +229,74 @@ protected override void ExecuteCore()
230
229
isTrimmable = selectedRuntimePack ? . IsTrimmable ;
231
230
}
232
231
233
- // Only add runtime packs where the framework reference name matches the RuntimeFrameworkName
234
- // Framework references for "profiles" will use the runtime pack from the corresponding non-profile framework
232
+ bool includeInPackageDownload ;
233
+ KnownRuntimePack runtimePackForRuntimeIDProcessing ;
235
234
if ( knownFrameworkReference . Name . Equals ( knownFrameworkReference . RuntimeFrameworkName , StringComparison . OrdinalIgnoreCase ) )
236
235
{
237
- bool processedPrimaryRuntimeIdentifier = false ;
236
+ // Only add runtime packs where the framework reference name matches the RuntimeFrameworkName
237
+ // Framework references for "profiles" will use the runtime pack from the corresponding non-profile framework
238
+ runtimePackForRuntimeIDProcessing = selectedRuntimePack . Value ;
239
+ includeInPackageDownload = true ;
240
+ }
241
+ else if ( ! knownFrameworkReference . RuntimePackRuntimeIdentifiers . Equals ( selectedRuntimePack ? . RuntimePackRuntimeIdentifiers ) )
242
+ {
243
+ // If the profile has a different set of runtime identifiers than the runtime pack, use the profile.
244
+ runtimePackForRuntimeIDProcessing = knownFrameworkReference . ToKnownRuntimePack ( ) ;
245
+ includeInPackageDownload = true ;
246
+ }
247
+ else
248
+ {
249
+ // For the remaining profiles, don't include them in package download but add them to unavaliable if necessary.
250
+ runtimePackForRuntimeIDProcessing = knownFrameworkReference . ToKnownRuntimePack ( ) ;
251
+ includeInPackageDownload = false ;
252
+ }
238
253
239
- if ( ( SelfContained || ReadyToRunEnabled ) &&
240
- ! string . IsNullOrEmpty ( RuntimeIdentifier ) &&
241
- selectedRuntimePack != null &&
242
- ! string . IsNullOrEmpty ( selectedRuntimePack ? . RuntimePackNamePatterns ) )
243
- {
254
+ bool processedPrimaryRuntimeIdentifier = false ;
244
255
245
- // Find other KnownFrameworkReferences that map to the same runtime pack, if any
246
- List < string > additionalFrameworkReferencesForRuntimePack = null ;
247
- foreach ( var additionalKnownFrameworkReference in knownFrameworkReferencesForTargetFramework )
256
+ if ( ( SelfContained || ReadyToRunEnabled ) &&
257
+ ! string . IsNullOrEmpty ( RuntimeIdentifier ) &&
258
+ selectedRuntimePack != null &&
259
+ ! string . IsNullOrEmpty ( selectedRuntimePack ? . RuntimePackNamePatterns ) )
260
+ {
261
+
262
+ // Find other KnownFrameworkReferences that map to the same runtime pack, if any
263
+ List < string > additionalFrameworkReferencesForRuntimePack = null ;
264
+ foreach ( var additionalKnownFrameworkReference in knownFrameworkReferencesForTargetFramework )
265
+ {
266
+ if ( additionalKnownFrameworkReference . RuntimeFrameworkName . Equals ( knownFrameworkReference . RuntimeFrameworkName , StringComparison . OrdinalIgnoreCase ) &&
267
+ ! additionalKnownFrameworkReference . RuntimeFrameworkName . Equals ( additionalKnownFrameworkReference . Name , StringComparison . OrdinalIgnoreCase ) )
248
268
{
249
- if ( additionalKnownFrameworkReference . RuntimeFrameworkName . Equals ( knownFrameworkReference . RuntimeFrameworkName , StringComparison . OrdinalIgnoreCase ) &&
250
- ! additionalKnownFrameworkReference . RuntimeFrameworkName . Equals ( additionalKnownFrameworkReference . Name , StringComparison . OrdinalIgnoreCase ) )
269
+ if ( additionalFrameworkReferencesForRuntimePack == null )
251
270
{
252
- if ( additionalFrameworkReferencesForRuntimePack == null )
253
- {
254
- additionalFrameworkReferencesForRuntimePack = new List < string > ( ) ;
255
- }
256
- additionalFrameworkReferencesForRuntimePack . Add ( additionalKnownFrameworkReference . Name ) ;
271
+ additionalFrameworkReferencesForRuntimePack = new List < string > ( ) ;
257
272
}
273
+ additionalFrameworkReferencesForRuntimePack . Add ( additionalKnownFrameworkReference . Name ) ;
258
274
}
275
+ }
259
276
260
- ProcessRuntimeIdentifier ( RuntimeIdentifier , selectedRuntimePack . Value , runtimePackVersion , additionalFrameworkReferencesForRuntimePack ,
261
- unrecognizedRuntimeIdentifiers , unavailableRuntimePacks , runtimePacks , packagesToDownload , isTrimmable ) ;
277
+ ProcessRuntimeIdentifier ( RuntimeIdentifier , runtimePackForRuntimeIDProcessing , runtimePackVersion , additionalFrameworkReferencesForRuntimePack ,
278
+ unrecognizedRuntimeIdentifiers , unavailableRuntimePacks , runtimePacks , packagesToDownload , isTrimmable , includeInPackageDownload ) ;
262
279
263
- processedPrimaryRuntimeIdentifier = true ;
264
- }
280
+ processedPrimaryRuntimeIdentifier = true ;
281
+ }
265
282
266
- if ( RuntimeIdentifiers != null )
283
+ if ( RuntimeIdentifiers != null )
284
+ {
285
+ foreach ( var runtimeIdentifier in RuntimeIdentifiers )
267
286
{
268
- foreach ( var runtimeIdentifier in RuntimeIdentifiers )
287
+ if ( processedPrimaryRuntimeIdentifier && runtimeIdentifier == this . RuntimeIdentifier )
269
288
{
270
- if ( processedPrimaryRuntimeIdentifier && runtimeIdentifier == this . RuntimeIdentifier )
271
- {
272
- // We've already processed this RID
273
- continue ;
274
- }
275
-
276
- // Pass in null for the runtimePacks list, as for these runtime identifiers we only want to
277
- // download the runtime packs, but not use the assets from them
278
- ProcessRuntimeIdentifier ( runtimeIdentifier , selectedRuntimePack . Value , runtimePackVersion , additionalFrameworkReferencesForRuntimePack : null ,
279
- unrecognizedRuntimeIdentifiers , unavailableRuntimePacks , runtimePacks : null , packagesToDownload , isTrimmable ) ;
289
+ // We've already processed this RID
290
+ continue ;
280
291
}
292
+
293
+ // Pass in null for the runtimePacks list, as for these runtime identifiers we only want to
294
+ // download the runtime packs, but not use the assets from them
295
+ ProcessRuntimeIdentifier ( runtimeIdentifier , runtimePackForRuntimeIDProcessing , runtimePackVersion , additionalFrameworkReferencesForRuntimePack : null ,
296
+ unrecognizedRuntimeIdentifiers , unavailableRuntimePacks , runtimePacks : null , packagesToDownload , isTrimmable , includeInPackageDownload ) ;
281
297
}
282
298
}
283
299
284
-
285
300
if ( ! string . IsNullOrEmpty ( knownFrameworkReference . RuntimeFrameworkName ) )
286
301
{
287
302
TaskItem runtimeFramework = new TaskItem ( knownFrameworkReference . RuntimeFrameworkName ) ;
@@ -370,7 +385,7 @@ protected override void ExecuteCore()
370
385
{
371
386
string runtimePackDescriptionForErrorMessage = knownFrameworkReference . RuntimeFrameworkName +
372
387
( requiredLabelsMetadata == string . Empty ? string . Empty : ":" + requiredLabelsMetadata ) ;
373
-
388
+
374
389
Log . LogError ( Strings . ConflictingRuntimePackInformation , runtimePackDescriptionForErrorMessage ,
375
390
string . Join ( Environment . NewLine , matchingRuntimePacks . Select ( rp => rp . RuntimePackNamePatterns ) ) ) ;
376
391
@@ -387,7 +402,8 @@ private void ProcessRuntimeIdentifier(
387
402
List < ITaskItem > unavailableRuntimePacks ,
388
403
List < ITaskItem > runtimePacks ,
389
404
List < ITaskItem > packagesToDownload ,
390
- string isTrimmable )
405
+ string isTrimmable ,
406
+ bool addToPackageDownload )
391
407
{
392
408
var runtimeGraph = new RuntimeGraphCache ( this ) . GetRuntimeGraph ( RuntimeGraphPath ) ;
393
409
var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = selectedRuntimePack . RuntimePackRuntimeIdentifiers . Split ( ';' ) ;
@@ -418,7 +434,7 @@ private void ProcessRuntimeIdentifier(
418
434
unrecognizedRuntimeIdentifiers . Add ( runtimeIdentifier ) ;
419
435
}
420
436
}
421
- else
437
+ else if ( addToPackageDownload )
422
438
{
423
439
foreach ( var runtimePackNamePattern in selectedRuntimePack . RuntimePackNamePatterns . Split ( ';' ) )
424
440
{
@@ -620,18 +636,13 @@ public KnownFrameworkReference(ITaskItem item)
620
636
// The framework name to write to the runtimeconfig file (and the name of the folder under dotnet/shared)
621
637
public string RuntimeFrameworkName => _item . GetMetadata ( MetadataKeys . RuntimeFrameworkName ) ;
622
638
public string DefaultRuntimeFrameworkVersion => _item . GetMetadata ( "DefaultRuntimeFrameworkVersion" ) ;
623
- //public string LatestRuntimeFrameworkVersion => _item.GetMetadata("LatestRuntimeFrameworkVersion");
624
639
625
640
// The ID of the targeting pack NuGet package to reference
626
641
public string TargetingPackName => _item . GetMetadata ( "TargetingPackName" ) ;
627
642
public string TargetingPackVersion => _item . GetMetadata ( "TargetingPackVersion" ) ;
628
643
public string TargetingPackFormat => _item . GetMetadata ( "TargetingPackFormat" ) ;
629
644
630
- //public string RuntimePackNamePatterns => _item.GetMetadata("RuntimePackNamePatterns");
631
-
632
- //public string RuntimePackRuntimeIdentifiers => _item.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers);
633
-
634
- //public string IsTrimmable => _item.GetMetadata(MetadataKeys.IsTrimmable);
645
+ public string RuntimePackRuntimeIdentifiers => _item . GetMetadata ( MetadataKeys . RuntimePackRuntimeIdentifiers ) ;
635
646
636
647
public bool IsWindowsOnly => _item . HasMetadataValue ( "IsWindowsOnly" , "true" ) ;
637
648
@@ -668,8 +679,6 @@ public KnownRuntimePack(ITaskItem item)
668
679
public string Name => _item . ItemSpec ;
669
680
670
681
//// The framework name to write to the runtimeconfig file (and the name of the folder under dotnet/shared)
671
- //public string RuntimeFrameworkName => _item.GetMetadata(MetadataKeys.RuntimeFrameworkName);
672
- //public string DefaultRuntimeFrameworkVersion => _item.GetMetadata("DefaultRuntimeFrameworkVersion");
673
682
public string LatestRuntimeFrameworkVersion => _item . GetMetadata ( "LatestRuntimeFrameworkVersion" ) ;
674
683
675
684
public string RuntimePackNamePatterns => _item . GetMetadata ( "RuntimePackNamePatterns" ) ;
0 commit comments