コード例 #1
0
        private static void SetFrameworks(IObjectWriter writer, IList <TargetFrameworkInformation> frameworks)
        {
            if (frameworks.Any())
            {
                writer.WriteObjectStart("frameworks");

                var frameworkSorter = new NuGetFrameworkSorter();
                foreach (var framework in frameworks.OrderBy(c => c.FrameworkName, frameworkSorter))
                {
                    writer.WriteObjectStart(framework.FrameworkName.GetShortFolderName());

                    SetDependencies(writer, framework.Dependencies);
                    SetCentralDependencies(writer, framework.CentralPackageVersions.Values);
                    SetImports(writer, framework.Imports);
                    SetValueIfTrue(writer, "assetTargetFallback", framework.AssetTargetFallback);
                    SetValueIfTrue(writer, "warn", framework.Warn);
                    SetDownloadDependencies(writer, framework.DownloadDependencies);
                    SetFrameworkReferences(writer, framework.FrameworkReferences);
                    SetValueIfNotNull(writer, "runtimeIdentifierGraphPath", framework.RuntimeIdentifierGraphPath);
                    writer.WriteObjectEnd();
                }

                writer.WriteObjectEnd();
            }
        }
コード例 #2
0
        private async Task <IEnumerable <PackageReference> > GetPackageReferencesAsync(PackageSpec packageSpec)
        {
            var frameworkSorter = new NuGetFrameworkSorter();

            var assetsFilePath = await GetAssetsFilePathAsync();

            var                    fileInfo          = new FileInfo(assetsFilePath);
            PackageSpec            assetsPackageSpec = default;
            IList <LockFileTarget> targets           = default;

            if (fileInfo.Exists && fileInfo.LastWriteTimeUtc > _lastTimeAssetsModified)
            {
                await TaskScheduler.Default;
                var lockFile = new LockFileFormat().Read(assetsFilePath);
                assetsPackageSpec = lockFile.PackageSpec;
                targets           = lockFile.Targets;

                _lastTimeAssetsModified = fileInfo.LastWriteTimeUtc;
            }

            return(packageSpec
                   .TargetFrameworks
                   .SelectMany(f => GetPackageReferences(f.Dependencies, f.FrameworkName, _installedPackages, assetsPackageSpec, targets))
                   .GroupBy(p => p.PackageIdentity)
                   .Select(g => g.OrderBy(p => p.TargetFramework, frameworkSorter).First()));
        }
コード例 #3
0
        private static PackageReference[] GetPackageReferences(PackageSpec packageSpec)
        {
            var frameworkSorter = new NuGetFrameworkSorter();

            return(packageSpec
                   .TargetFrameworks
                   .SelectMany(f => GetPackageReferences(f.Dependencies, f.FrameworkName))
                   .GroupBy(p => p.PackageIdentity)
                   .Select(g => g.OrderBy(p => p.TargetFramework, frameworkSorter).First())
                   .ToArray());
        }
コード例 #4
0
        private static void WriteMetadataTargetFrameworks(IObjectWriter writer, ProjectRestoreMetadata msbuildMetadata)
        {
            if (msbuildMetadata.TargetFrameworks?.Count > 0)
            {
                writer.WriteObjectStart("frameworks");

                var frameworkNames  = new HashSet <string>();
                var frameworkSorter = new NuGetFrameworkSorter();
                foreach (var framework in msbuildMetadata.TargetFrameworks.OrderBy(c => c.FrameworkName, frameworkSorter))
                {
                    var frameworkName = framework.FrameworkName.GetShortFolderName();

                    if (!frameworkNames.Contains(frameworkName))
                    {
                        frameworkNames.Add(frameworkName);

                        writer.WriteObjectStart(frameworkName);

                        SetValueIfNotNull(writer, "targetAlias", framework.TargetAlias);

                        writer.WriteObjectStart("projectReferences");

                        foreach (var project in framework.ProjectReferences.OrderBy(e => e.ProjectPath, PathUtility.GetStringComparerBasedOnOS()))
                        {
                            writer.WriteObjectStart(project.ProjectUniqueName);

                            writer.WriteNameValue("projectPath", project.ProjectPath);

                            if (project.IncludeAssets != LibraryIncludeFlags.All)
                            {
                                writer.WriteNameValue("includeAssets", LibraryIncludeFlagUtils.GetFlagString(project.IncludeAssets));
                            }

                            if (project.ExcludeAssets != LibraryIncludeFlags.None)
                            {
                                writer.WriteNameValue("excludeAssets", LibraryIncludeFlagUtils.GetFlagString(project.ExcludeAssets));
                            }

                            if (project.PrivateAssets != LibraryIncludeFlagUtils.DefaultSuppressParent)
                            {
                                writer.WriteNameValue("privateAssets", LibraryIncludeFlagUtils.GetFlagString(project.PrivateAssets));
                            }

                            writer.WriteObjectEnd();
                        }

                        writer.WriteObjectEnd();
                        writer.WriteObjectEnd();
                    }
                }

                writer.WriteObjectEnd();
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets the both the installed (top level) and transitive package references for this project.
        /// Returns the package reference as two separate lists (installed and transitive).
        /// </summary>
        public override async Task <ProjectPackages> GetInstalledAndTransitivePackagesAsync(CancellationToken token)
        {
            PackageSpec packageSpec = await GetPackageSpecAsync(NullSettings.Instance);

            var frameworkSorter = new NuGetFrameworkSorter();

            string assetsFilePath = await GetAssetsFilePathAsync();

            var fileInfo = new FileInfo(assetsFilePath);
            IList <LockFileTarget> targets = default;

            if (fileInfo.Exists && fileInfo.LastWriteTimeUtc > _lastTimeAssetsModified)
            {
                await TaskScheduler.Default;
                LockFile lockFile = LockFileUtilities.GetLockFile(assetsFilePath, NullLogger.Instance);
                if (!(lockFile is null))
                {
                    targets = lockFile.Targets;

                    _lastTimeAssetsModified = fileInfo.LastWriteTimeUtc;

                    // clear the transitive packages cache, since we don't know when a dependency has been removed
                    _transitivePackages.Clear();
                }
            }

            // get the installed packages
            IEnumerable <PackageReference> installedPackages = packageSpec
                                                               .TargetFrameworks
                                                               .SelectMany(f => GetPackageReferences(f.Dependencies, f.FrameworkName, _installedPackages, targets))
                                                               .GroupBy(p => p.PackageIdentity)
                                                               .Select(g => g.OrderBy(p => p.TargetFramework, frameworkSorter).First());

            // get the transitive packages, excluding any already contained in the installed packages
            IEnumerable <PackageReference> transitivePackages = packageSpec
                                                                .TargetFrameworks
                                                                .SelectMany(f => GetTransitivePackageReferences(f.FrameworkName, _installedPackages, _transitivePackages, targets))
                                                                .GroupBy(p => p.PackageIdentity)
                                                                .Select(g => g.OrderBy(p => p.TargetFramework, frameworkSorter).First());

            return(new ProjectPackages(installedPackages.ToList(), transitivePackages.ToList()));
        }
コード例 #6
0
        private static void SetFrameworks(IObjectWriter writer, IList <TargetFrameworkInformation> frameworks)
        {
            if (frameworks.Any())
            {
                writer.WriteObjectStart("frameworks");

                var frameworkSorter = new NuGetFrameworkSorter();
                foreach (var framework in frameworks.OrderBy(c => c.FrameworkName, frameworkSorter))
                {
                    writer.WriteObjectStart(framework.FrameworkName.GetShortFolderName());

                    SetDependencies(writer, framework.Dependencies);
                    SetImports(writer, framework.Imports);
                    SetValueIfTrue(writer, "assetTargetFallback", framework.AssetTargetFallback);
                    SetValueIfTrue(writer, "warn", framework.Warn);

                    writer.WriteObjectEnd();
                }

                writer.WriteObjectEnd();
            }
        }