コード例 #1
0
        protected override void ExecuteCore()
        {
            if (FrameworkReferences.Length == 0)
            {
                return;
            }

            var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(tp => tp.ItemSpec, StringComparer.OrdinalIgnoreCase);
            var resolvedRuntimePacks   = ResolvedRuntimePacks.ToDictionary(rp => rp.GetMetadata(MetadataKeys.FrameworkName), StringComparer.OrdinalIgnoreCase);

            var resolvedFrameworkReferences = new List <TaskItem>(FrameworkReferences.Length);

            foreach (var frameworkReference in FrameworkReferences)
            {
                ITaskItem targetingPack;
                if (!resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack))
                {
                    //  FrameworkReference didn't resolve to a targeting pack
                    continue;
                }

                TaskItem resolvedFrameworkReference = new TaskItem(frameworkReference.ItemSpec);
                resolvedFrameworkReference.SetMetadata(MetadataKeys.OriginalItemSpec, frameworkReference.ItemSpec);
                resolvedFrameworkReference.SetMetadata(MetadataKeys.IsImplicitlyDefined, frameworkReference.GetMetadata(MetadataKeys.IsImplicitlyDefined));

                resolvedFrameworkReference.SetMetadata("TargetingPackPath", targetingPack.GetMetadata(MetadataKeys.Path));
                resolvedFrameworkReference.SetMetadata("TargetingPackName", targetingPack.GetMetadata(MetadataKeys.NuGetPackageId));
                resolvedFrameworkReference.SetMetadata("TargetingPackVersion", targetingPack.GetMetadata(MetadataKeys.NuGetPackageVersion));
                resolvedFrameworkReference.SetMetadata("Profile", targetingPack.GetMetadata("Profile"));

                ITaskItem runtimePack;
                if (resolvedRuntimePacks.TryGetValue(frameworkReference.ItemSpec, out runtimePack))
                {
                    resolvedFrameworkReference.SetMetadata("RuntimePackPath", runtimePack.GetMetadata(MetadataKeys.PackageDirectory));
                    resolvedFrameworkReference.SetMetadata("RuntimePackName", runtimePack.GetMetadata(MetadataKeys.NuGetPackageId));
                    resolvedFrameworkReference.SetMetadata("RuntimePackVersion", runtimePack.GetMetadata(MetadataKeys.NuGetPackageVersion));
                }

                resolvedFrameworkReferences.Add(resolvedFrameworkReference);
            }

            ResolvedFrameworkReferences = resolvedFrameworkReferences.ToArray();
        }
コード例 #2
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();
        }
コード例 #3
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
                {
                    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();
        }
コード例 #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>();
            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);
        }