diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs index 792c578a70f8..db6794618092 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs @@ -127,17 +127,15 @@ public class ProcessFrameworkReferences : TaskBase private Version _normalizedTargetFrameworkVersion; - protected override void ExecuteCore() + void AddPacksForFrameworkReferences( + List packagesToDownload, + List runtimeFrameworks, + List targetingPacks, + List runtimePacks, + List unavailableRuntimePacks, + out List knownRuntimePacksForTargetFramework + ) { - // Perf optimization: If there are no FrameworkReference items, then don't do anything - // (This means that if you don't have any direct framework references, you won't get any transitive ones either - if (FrameworkReferences == null || FrameworkReferences.Length == 0) - { - return; - } - - _normalizedTargetFrameworkVersion = NormalizeVersion(new Version(TargetFrameworkVersion)); - var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences .Select(item => new KnownFrameworkReference(item)) @@ -147,7 +145,7 @@ protected override void ExecuteCore() // Get known runtime packs from known framework references. // Only use items where the framework reference name matches the RuntimeFrameworkName. // This will filter out known framework references for "profiles", ie WindowsForms and WPF - var knownRuntimePacksForTargetFramework = + knownRuntimePacksForTargetFramework = knownFrameworkReferencesForTargetFramework .Where(kfr => kfr.Name.Equals(kfr.RuntimeFrameworkName, StringComparison.OrdinalIgnoreCase)) .Select(kfr => kfr.ToKnownRuntimePack()) @@ -160,12 +158,6 @@ protected override void ExecuteCore() var frameworkReferenceMap = FrameworkReferences.ToDictionary(fr => fr.ItemSpec, StringComparer.OrdinalIgnoreCase); - List packagesToDownload = new List(); - List runtimeFrameworks = new List(); - List targetingPacks = new List(); - List runtimePacks = new List(); - List unavailableRuntimePacks = new List(); - HashSet unrecognizedRuntimeIdentifiers = new HashSet(StringComparer.OrdinalIgnoreCase); bool windowsOnlyErrorLogged = false; @@ -367,6 +359,39 @@ var runtimeRequiredByDeployment runtimeFrameworks.Add(runtimeFramework); } } + } + + protected override void ExecuteCore() + { + List packagesToDownload = null; + List runtimeFrameworks = null; + List targetingPacks = null; + List runtimePacks = null; + List unavailableRuntimePacks = null; + List knownRuntimePacksForTargetFramework = null; + + // Perf optimization: If there are no FrameworkReference items, then don't do anything + // (This means that if you don't have any direct framework references, you won't get any transitive ones either + if (FrameworkReferences != null && FrameworkReferences.Length != 0) + { + _normalizedTargetFrameworkVersion = NormalizeVersion(new Version(TargetFrameworkVersion)); + + packagesToDownload = new List(); + runtimeFrameworks = new List(); + targetingPacks = new List(); + runtimePacks = new List(); + unavailableRuntimePacks = new List(); + AddPacksForFrameworkReferences( + packagesToDownload, + runtimeFrameworks, + targetingPacks, + runtimePacks, + unavailableRuntimePacks, + out knownRuntimePacksForTargetFramework); + } + + _normalizedTargetFrameworkVersion ??= NormalizeVersion(new Version(TargetFrameworkVersion)); + packagesToDownload ??= new List(); List implicitPackageReferences = new List(); @@ -417,22 +442,22 @@ var runtimeRequiredByDeployment PackagesToDownload = packagesToDownload.Distinct(new PackageToDownloadComparer()).ToArray(); } - if (runtimeFrameworks.Any()) + if (runtimeFrameworks?.Any() == true) { RuntimeFrameworks = runtimeFrameworks.ToArray(); } - if (targetingPacks.Any()) + if (targetingPacks?.Any() == true) { TargetingPacks = targetingPacks.ToArray(); } - if (runtimePacks.Any()) + if (runtimePacks?.Any() == true) { RuntimePacks = runtimePacks.ToArray(); } - if (unavailableRuntimePacks.Any()) + if (unavailableRuntimePacks?.Any() == true) { UnavailableRuntimePacks = unavailableRuntimePacks.ToArray(); } @@ -442,22 +467,25 @@ var runtimeRequiredByDeployment ImplicitPackageReferences = implicitPackageReferences.ToArray(); } - // Determine the known runtime identifier platforms based on all available Microsoft.NETCore.App packs - HashSet knownRuntimeIdentifierPlatforms = new HashSet(StringComparer.OrdinalIgnoreCase); - var netCoreAppPacks = knownRuntimePacksForTargetFramework.Where(krp => krp.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)); - foreach (KnownRuntimePack netCoreAppPack in netCoreAppPacks) + if (knownRuntimePacksForTargetFramework?.Any() == true) { - foreach (var runtimeIdentifier in netCoreAppPack.RuntimePackRuntimeIdentifiers.Split(';')) + // Determine the known runtime identifier platforms based on all available Microsoft.NETCore.App packs + HashSet knownRuntimeIdentifierPlatforms = new HashSet(StringComparer.OrdinalIgnoreCase); + var netCoreAppPacks = knownRuntimePacksForTargetFramework!.Where(krp => krp.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)); + foreach (KnownRuntimePack netCoreAppPack in netCoreAppPacks) { - int separator = runtimeIdentifier.LastIndexOf('-'); - string platform = separator < 0 ? runtimeIdentifier : runtimeIdentifier.Substring(0, separator); - knownRuntimeIdentifierPlatforms.Add(platform); + foreach (var runtimeIdentifier in netCoreAppPack.RuntimePackRuntimeIdentifiers.Split(';')) + { + int separator = runtimeIdentifier.LastIndexOf('-'); + string platform = separator < 0 ? runtimeIdentifier : runtimeIdentifier.Substring(0, separator); + knownRuntimeIdentifierPlatforms.Add(platform); + } } - } - if (knownRuntimeIdentifierPlatforms.Count > 0) - { - KnownRuntimeIdentifierPlatforms = knownRuntimeIdentifierPlatforms.ToArray(); + if (knownRuntimeIdentifierPlatforms.Count > 0) + { + KnownRuntimeIdentifierPlatforms = knownRuntimeIdentifierPlatforms.ToArray(); + } } } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index c35faba0271f..345bf8a69a9c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -1,4 +1,4 @@ -