Exemple #1
0
        protected override void ExecuteCore()
        {
            var runtimePackAssets = new List <ITaskItem>();

            HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase);

            foreach (var unavailableRuntimePack in UnavailableRuntimePacks)
            {
                if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec))
                {
                    //  This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier
                    //  NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'.
                    Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec,
                                 unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
                }
            }

            HashSet <string> processedRuntimePackRoots = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var runtimePack in ResolvedRuntimePacks)
            {
                if (!frameworkReferenceNames.Contains(runtimePack.GetMetadata(MetadataKeys.FrameworkName)))
                {
                    //  This is a runtime pack for a shared framework that ultimately wasn't referenced, so don't include its assets
                    continue;
                }

                string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory);

                if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot))
                {
                    //  If we do the work in https://github.com/dotnet/cli/issues/10528,
                    //  then we should add a new error message here indicating that the runtime pack hasn't
                    //  been downloaded, and that restore should be run with that runtime identifier.
                    Log.LogError(Strings.NoRuntimePackAvailable, runtimePack.ItemSpec,
                                 runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
                }

                if (!processedRuntimePackRoots.Add(runtimePackRoot))
                {
                    //  We already added assets from this runtime pack (which can happen with FrameworkReferences to different
                    //  profiles of the same shared framework)
                    continue;
                }

                var runtimeListPath = Path.Combine(runtimePackRoot, "data", "RuntimeListList.xml");

                if (File.Exists(runtimeListPath))
                {
                    AddRuntimePackAssetsFromManifest(runtimePackAssets, runtimePackRoot, runtimeListPath, runtimePack);
                }
                else
                {
                    runtimePackAssets.AddRange(GetRuntimePackAssetsFromConvention(runtimePackRoot, runtimePack));
                }
            }

            RuntimePackAssets = runtimePackAssets.ToArray();
        }
Exemple #2
0
        public override bool Execute()
        {
            var log = new MSBuildLogger(Log);

            log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
            log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
            log.LogDebug($"(in) FrameworkReferences '{string.Join(";", FrameworkReferences.Select(p => p.ItemSpec))}'");

            var entries = new List <ITaskItem>();
            var seenIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var msbuildItem in FrameworkReferences)
            {
                var frameworkReference = msbuildItem.ItemSpec;

                if (string.IsNullOrEmpty(frameworkReference) || !seenIds.Add(frameworkReference))
                {
                    // Skip empty or already processed ids
                    continue;
                }

                var properties = new Dictionary <string, string>();
                properties.Add("ProjectUniqueName", ProjectUniqueName);
                properties.Add("Type", "FrameworkReference");
                properties.Add("Id", frameworkReference);

                if (!string.IsNullOrEmpty(TargetFrameworks))
                {
                    properties.Add("TargetFrameworks", TargetFrameworks);
                }
                BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "PrivateAssets");

                entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties));
            }

            RestoreGraphItems = entries.ToArray();

            return(true);
        }
        protected override void ExecuteCore()
        {
            var runtimePackAssets = new List <ITaskItem>();

            HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase);

            foreach (var unavailableRuntimePack in UnavailableRuntimePacks)
            {
                if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec))
                {
                    //  This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier
                    //  NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'.
                    Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec,
                                 unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
                }
            }

            HashSet <string> processedRuntimePackRoots = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var runtimePack in ResolvedRuntimePacks)
            {
                if (!frameworkReferenceNames.Contains(runtimePack.GetMetadata(MetadataKeys.FrameworkName)))
                {
                    //  This is a runtime pack for a shared framework that ultimately wasn't referenced, so don't include its assets
                    continue;
                }

                string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory);

                if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot))
                {
                    if (!DesignTimeBuild)
                    {
                        //  Don't treat this as an error if we are doing a design-time build.  This is because the design-time
                        //  build needs to succeed in order to get the right information in order to run a restore to download
                        //  the runtime pack.
                        Log.LogError(Strings.RuntimePackNotDownloaded, runtimePack.ItemSpec,
                                     runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
                    }
                    continue;
                }

                if (!processedRuntimePackRoots.Add(runtimePackRoot))
                {
                    //  We already added assets from this runtime pack (which can happen with FrameworkReferences to different
                    //  profiles of the same shared framework)
                    continue;
                }

                var runtimeListPath = Path.Combine(runtimePackRoot, "data", "RuntimeList.xml");

                if (File.Exists(runtimeListPath))
                {
                    AddRuntimePackAssetsFromManifest(runtimePackAssets, runtimePackRoot, runtimeListPath, runtimePack);
                }
                else
                {
                    throw new BuildErrorException(string.Format(Strings.RuntimeListNotFound, runtimeListPath));
                }
            }

            RuntimePackAssets = runtimePackAssets.ToArray();
        }
Exemple #4
0
        protected override void ExecuteCore()
        {
            List <TaskItem> referencesToAdd   = new List <TaskItem>();
            List <TaskItem> platformManifests = new List <TaskItem>();

            PackageConflictPreferredPackages = string.Empty;
            List <TaskItem> packageConflictOverrides = new List <TaskItem>();

            var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(item => item.ItemSpec, StringComparer.OrdinalIgnoreCase);

            foreach (var frameworkReference in FrameworkReferences)
            {
                ITaskItem targetingPack;
                resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack);
                string targetingPackRoot = targetingPack?.GetMetadata("Path");

                if (string.IsNullOrEmpty(targetingPackRoot) || !Directory.Exists(targetingPackRoot))
                {
                    if (GenerateErrorForMissingTargetingPacks)
                    {
                        Log.LogError(Strings.UnknownFrameworkReference, frameworkReference.ItemSpec);
                    }
                }
                else
                {
                    string targetingPackFormat = targetingPack.GetMetadata("TargetingPackFormat");

                    if (targetingPackFormat.Equals("NETStandardLegacy", StringComparison.OrdinalIgnoreCase))
                    {
                        AddNetStandardTargetingPackAssets(targetingPack, targetingPackRoot, referencesToAdd);
                    }
                    else
                    {
                        string targetingPackTargetFramework = targetingPack.GetMetadata("TargetFramework");
                        if (string.IsNullOrEmpty(targetingPackTargetFramework))
                        {
                            targetingPackTargetFramework = "netcoreapp3.0";
                        }

                        string   targetingPackDataPath = Path.Combine(targetingPackRoot, "data");
                        string[] possibleDllFolders    = new[]
                        {
                            Path.Combine(targetingPackRoot, "ref", targetingPackTargetFramework),
                            targetingPackDataPath
                        };

                        string[] possibleManifestPaths = new[]
                        {
                            Path.Combine(targetingPackRoot, "build", targetingPackTargetFramework,
                                         targetingPack.GetMetadata(MetadataKeys.PackageName) + ".PlatformManifest.txt"),
                            Path.Combine(targetingPackDataPath, "PlatformManifest.txt"),
                            Path.Combine(targetingPackDataPath,
                                         targetingPack.GetMetadata(MetadataKeys.PackageName) + ".PlatformManifest.txt"),
                        };

                        string targetingPackDllFolder = possibleDllFolders.First(path =>
                                                                                 Directory.Exists(path) &&
                                                                                 Directory.GetFiles(path, "*.dll").Any());

                        string platformManifestPath = possibleManifestPaths.FirstOrDefault(File.Exists);

                        string packageOverridesPath = Path.Combine(targetingPackDataPath, "PackageOverrides.txt");

                        string frameworkListPath = Path.Combine(targetingPackDataPath, "FrameworkList.xml");

                        if (File.Exists(frameworkListPath))
                        {
                            AddReferencesFromFrameworkList(frameworkListPath, targetingPackDllFolder,
                                                           targetingPack, referencesToAdd);
                        }
                        else
                        {
                            foreach (var dll in Directory.GetFiles(targetingPackDllFolder, "*.dll"))
                            {
                                var reference = CreateReferenceItem(dll, targetingPack);

                                referencesToAdd.Add(reference);
                            }
                        }

                        if (platformManifestPath != null)
                        {
                            platformManifests.Add(new TaskItem(platformManifestPath));
                        }

                        if (File.Exists(packageOverridesPath))
                        {
                            packageConflictOverrides.Add(CreatePackageOverride(targetingPack.GetMetadata("RuntimeFrameworkName"), packageOverridesPath));
                        }

                        if (targetingPack.ItemSpec.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase))
                        {
                            //  Hardcode this for now.  Load this from the targeting pack once we have "real" targeting packs
                            //  https://github.com/dotnet/cli/issues/10581
                            PackageConflictPreferredPackages = "Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App";
                        }
                    }
                }
            }

            //  Calculate which RuntimeFramework items should actually be used based on framework references
            HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(fr => fr.ItemSpec), StringComparer.OrdinalIgnoreCase);

            UsedRuntimeFrameworks = RuntimeFrameworks.Where(rf => frameworkReferenceNames.Contains(rf.GetMetadata(MetadataKeys.FrameworkName)))
                                    .ToArray();

            //  Filter out duplicate references (which can happen when referencing two different profiles that overlap)
            List <TaskItem> deduplicatedReferences = DeduplicateItems(referencesToAdd);

            ReferencesToAdd = deduplicatedReferences.Distinct().ToArray();

            PlatformManifests        = platformManifests.ToArray();
            PackageConflictOverrides = packageConflictOverrides.ToArray();
        }
        protected override void ExecuteCore()
        {
            var runtimePackAssets = new List <ITaskItem>();

            HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase);

            foreach (var unavailableRuntimePack in UnavailableRuntimePacks)
            {
                if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec))
                {
                    //  This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier
                    //  NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'.
                    Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec,
                                 unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
                }
            }

            HashSet <string> processedRuntimePackRoots = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var runtimePack in ResolvedRuntimePacks)
            {
                if (!frameworkReferenceNames.Contains(runtimePack.GetMetadata(MetadataKeys.FrameworkName)))
                {
                    //  This is a runtime pack for a shared framework that ultimately wasn't referenced, so don't include its assets
                    continue;
                }

                string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory);

                if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot))
                {
                    //  If we do the work in https://github.com/dotnet/cli/issues/10528,
                    //  then we should add a new error message here indicating that the runtime pack hasn't
                    //  been downloaded, and that restore should be run with that runtime identifier.
                    Log.LogError(Strings.NoRuntimePackAvailable, runtimePack.ItemSpec,
                                 runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
                }

                if (!processedRuntimePackRoots.Add(runtimePackRoot))
                {
                    //  We already added assets from this runtime pack (which can happen with FrameworkReferences to different
                    //  profiles of the same shared framework)
                    continue;
                }

                string runtimeIdentifier = runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier);

                //  These hard-coded paths are temporary until we have "real" runtime packs, which will likely have a flattened
                //  folder structure and a manifest indicating how the files should be used: https://github.com/dotnet/cli/issues/10442
                string runtimeAssetsPath = Path.Combine(runtimePackRoot, "runtimes", runtimeIdentifier, "lib", "netcoreapp3.0");
                string nativeAssetsPath  = Path.Combine(runtimePackRoot, "runtimes", runtimeIdentifier, "native");

                var runtimeAssets = Directory.Exists(runtimeAssetsPath) ? Directory.GetFiles(runtimeAssetsPath) : Array.Empty <string>();
                var nativeAssets  = Directory.Exists(nativeAssetsPath) ? Directory.GetFiles(nativeAssetsPath) : Array.Empty <string>();

                void AddAsset(string assetPath, string assetType)
                {
                    if (assetPath.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase) ||
                        assetPath.EndsWith(".map", StringComparison.OrdinalIgnoreCase) ||
                        assetPath.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) ||
                        assetPath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) ||
                        assetPath.EndsWith(".json", StringComparison.OrdinalIgnoreCase) ||
                        assetPath.EndsWith("._", StringComparison.Ordinal))
                    {
                        //  Don't add assets for these files (shouldn't be necessary if/once we have a manifest in the runtime pack
                        //  https://github.com/dotnet/cli/issues/10442
                        return;
                    }

                    var assetItem = new TaskItem(assetPath);

                    assetItem.SetMetadata(MetadataKeys.CopyLocal, "true");
                    assetItem.SetMetadata(MetadataKeys.DestinationSubPath, Path.GetFileName(assetPath));
                    assetItem.SetMetadata(MetadataKeys.AssetType, assetType);
                    assetItem.SetMetadata(MetadataKeys.PackageName, runtimePack.GetMetadata(MetadataKeys.PackageName));
                    assetItem.SetMetadata(MetadataKeys.PackageVersion, runtimePack.GetMetadata(MetadataKeys.PackageVersion));
                    assetItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier);
                    assetItem.SetMetadata(MetadataKeys.IsTrimmable, runtimePack.GetMetadata(MetadataKeys.IsTrimmable));

                    runtimePackAssets.Add(assetItem);
                }

                foreach (var asset in runtimeAssets)
                {
                    AddAsset(asset, "runtime");
                }
                foreach (var asset in nativeAssets)
                {
                    AddAsset(asset, "native");
                }

                runtimePackAssets.AddRange(EnumerateResourceAssets(runtimePackRoot, runtimeIdentifier, runtimePack));
            }

            RuntimePackAssets = runtimePackAssets.ToArray();
        }
        protected override void ExecuteCore()
        {
            List <TaskItem> referencesToAdd   = new List <TaskItem>();
            List <TaskItem> platformManifests = new List <TaskItem>();

            PackageConflictPreferredPackages = string.Empty;
            List <TaskItem> packageConflictOverrides = new List <TaskItem>();

            var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(item => item.ItemSpec, StringComparer.OrdinalIgnoreCase);

            foreach (var frameworkReference in FrameworkReferences)
            {
                ITaskItem targetingPack;
                resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack);
                string targetingPackRoot = targetingPack?.GetMetadata("Path");

                if (string.IsNullOrEmpty(targetingPackRoot) || !Directory.Exists(targetingPackRoot))
                {
                    if (GenerateErrorForMissingTargetingPacks)
                    {
                        Log.LogError(Strings.UnknownFrameworkReference, frameworkReference.ItemSpec);
                    }
                }
                else
                {
                    foreach (var dll in Directory.GetFiles(Path.Combine(targetingPackRoot, "ref", "netcoreapp3.0"), "*.dll"))
                    {
                        var reference = new TaskItem(dll);

                        reference.SetMetadata(MetadataKeys.ExternallyResolved, "true");
                        reference.SetMetadata(MetadataKeys.Private, "false");

                        //  TODO: Once we work out what metadata we should use here to display these references grouped under the targeting pack
                        //  in solution explorer, set that metadata here.These metadata values are based on what PCLs were using.
                        //  https://github.com/dotnet/sdk/issues/2802
                        reference.SetMetadata("WinMDFile", "false");
                        reference.SetMetadata("ReferenceGroupingDisplayName", targetingPack.ItemSpec);
                        reference.SetMetadata("ReferenceGrouping", targetingPack.ItemSpec);
                        reference.SetMetadata("ResolvedFrom", "TargetingPack");
                        reference.SetMetadata("IsSystemReference", "true");

                        referencesToAdd.Add(reference);
                    }

                    var platformManifestPath = Path.Combine(targetingPackRoot, "build", "netcoreapp3.0",
                                                            targetingPack.GetMetadata(MetadataKeys.PackageName) + ".PlatformManifest.txt");

                    if (File.Exists(platformManifestPath))
                    {
                        platformManifests.Add(new TaskItem(platformManifestPath));
                    }

                    if (targetingPack.ItemSpec.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase))
                    {
                        //  Hardcode this for now.  Load this from the targeting pack once we have "real" targeting packs
                        //  https://github.com/dotnet/cli/issues/10581
                        PackageConflictPreferredPackages = "Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App";
                    }
                }
            }

            HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(fr => fr.ItemSpec), StringComparer.OrdinalIgnoreCase);

            RuntimeFrameworksToRemove = RuntimeFrameworks.Where(rf => !frameworkReferenceNames.Contains(rf.GetMetadata(MetadataKeys.FrameworkName)))
                                        .ToArray();

            ReferencesToAdd          = referencesToAdd.ToArray();
            PlatformManifests        = platformManifests.ToArray();
            PackageConflictOverrides = packageConflictOverrides.ToArray();
        }
Exemple #7
0
        protected override void ExecuteCore()
        {
            List <TaskItem> referencesToAdd   = new List <TaskItem>();
            List <TaskItem> platformManifests = new List <TaskItem>();

            PackageConflictPreferredPackages = string.Empty;
            List <TaskItem> packageConflictOverrides = new List <TaskItem>();
            List <string>   preferredPackages        = new List <string>();

            var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(item => item.ItemSpec, StringComparer.OrdinalIgnoreCase);

            foreach (var frameworkReference in FrameworkReferences)
            {
                ITaskItem targetingPack;
                resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack);
                string targetingPackRoot = targetingPack?.GetMetadata(MetadataKeys.Path);

                if (string.IsNullOrEmpty(targetingPackRoot) || !Directory.Exists(targetingPackRoot))
                {
                    if (GenerateErrorForMissingTargetingPacks)
                    {
                        Log.LogError(Strings.UnknownFrameworkReference, frameworkReference.ItemSpec);
                    }
                }
                else
                {
                    string targetingPackFormat = targetingPack.GetMetadata("TargetingPackFormat");

                    if (targetingPackFormat.Equals("NETStandardLegacy", StringComparison.OrdinalIgnoreCase))
                    {
                        AddNetStandardTargetingPackAssets(targetingPack, targetingPackRoot, referencesToAdd);
                    }
                    else
                    {
                        string targetingPackTargetFramework = targetingPack.GetMetadata("TargetFramework");
                        if (string.IsNullOrEmpty(targetingPackTargetFramework))
                        {
                            targetingPackTargetFramework = "netcoreapp3.0";
                        }

                        string targetingPackDataPath = Path.Combine(targetingPackRoot, "data");

                        string targetingPackDllFolder = Path.Combine(targetingPackRoot, "ref", targetingPackTargetFramework);

                        //  Fall back to netcoreapp5.0 folder if looking for net5.0 and it's not found
                        if (!Directory.Exists(targetingPackDllFolder) &&
                            targetingPackTargetFramework.Equals("net5.0", StringComparison.OrdinalIgnoreCase))
                        {
                            targetingPackTargetFramework = "netcoreapp5.0";
                            targetingPackDllFolder       = Path.Combine(targetingPackRoot, "ref", targetingPackTargetFramework);
                        }

                        string platformManifestPath = Path.Combine(targetingPackDataPath, "PlatformManifest.txt");

                        string packageOverridesPath = Path.Combine(targetingPackDataPath, "PackageOverrides.txt");

                        string frameworkListPath = Path.Combine(targetingPackDataPath, "FrameworkList.xml");

                        AddReferencesFromFrameworkList(frameworkListPath, targetingPackDllFolder,
                                                       targetingPack, referencesToAdd);

                        if (File.Exists(platformManifestPath))
                        {
                            platformManifests.Add(new TaskItem(platformManifestPath));
                        }

                        if (File.Exists(packageOverridesPath))
                        {
                            packageConflictOverrides.Add(CreatePackageOverride(targetingPack.GetMetadata(MetadataKeys.NuGetPackageId), packageOverridesPath));
                        }

                        preferredPackages.AddRange(targetingPack.GetMetadata(MetadataKeys.PackageConflictPreferredPackages).Split(';'));
                    }
                }
            }

            //  Calculate which RuntimeFramework items should actually be used based on framework references
            HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(fr => fr.ItemSpec), StringComparer.OrdinalIgnoreCase);

            UsedRuntimeFrameworks = RuntimeFrameworks.Where(rf => frameworkReferenceNames.Contains(rf.GetMetadata(MetadataKeys.FrameworkName)))
                                    .ToArray();

            //  Filter out duplicate references (which can happen when referencing two different profiles that overlap)
            List <TaskItem> deduplicatedReferences = DeduplicateItems(referencesToAdd);

            ReferencesToAdd = deduplicatedReferences.Distinct().ToArray();

            PlatformManifests                = platformManifests.ToArray();
            PackageConflictOverrides         = packageConflictOverrides.ToArray();
            PackageConflictPreferredPackages = string.Join(";", preferredPackages);
        }
Exemple #8
0
 public FrameworkReferenceGroup AsReadOnly()
 {
     return(new FrameworkReferenceGroup(TargetFramework, FrameworkReferences.Select(fr => new FrameworkReference(fr))));
 }