Ejemplo n.º 1
0
        public Library GetDescription(LibraryRange libraryRange, NuGetFramework targetFramework)
        {
            string name = libraryRange.Name;

            PackageSpec packageSpec;

            // Can't find a project file with the name so bail
            if (!_resolver.TryResolvePackageSpec(name, out packageSpec))
            {
                return(null);
            }

            // This never returns null
            var targetFrameworkInfo         = packageSpec.GetTargetFramework(targetFramework);
            var targetFrameworkDependencies = targetFrameworkInfo.Dependencies;

            if (targetFramework.IsDesktop())
            {
                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "mscorlib",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });

                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "System",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });

                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "System.Core",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });

                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "Microsoft.CSharp",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });
            }

            var dependencies = packageSpec.Dependencies.Concat(targetFrameworkDependencies).ToList();

            // Mark the library as unresolved if there were specified frameworks
            // and none of them resolved
            bool unresolved = targetFrameworkInfo.FrameworkName == null &&
                              packageSpec.TargetFrameworks.Any();

            var library = new Library
            {
                LibraryRange = libraryRange,
                Identity     = new LibraryIdentity
                {
                    Name    = packageSpec.Name,
                    Version = packageSpec.Version,
                    Type    = LibraryTypes.Project,
                },
                Path         = packageSpec.FilePath,
                Dependencies = dependencies,
                Resolved     = !unresolved,

                [KnownLibraryProperties.PackageSpec] = packageSpec
            };

            return(library);
        }
        public Library GetLibrary(LibraryRange libraryRange, NuGetFramework targetFramework)
        {
            var name = libraryRange.Name;

            PackageSpec packageSpec;

            // Can't find a project file with the name so bail
            if (!_resolver.TryResolvePackageSpec(name, out packageSpec))
            {
                return(null);
            }

            // This never returns null
            var targetFrameworkInfo         = packageSpec.GetTargetFramework(targetFramework);
            var targetFrameworkDependencies = targetFrameworkInfo.Dependencies;

            if (targetFramework.IsDesktop())
            {
                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "mscorlib",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });

                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "System",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });

                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "System.Core",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });

                targetFrameworkDependencies.Add(new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = "Microsoft.CSharp",
                        TypeConstraint = LibraryTypes.Reference
                    }
                });
            }

            var dependencies = packageSpec.Dependencies.Concat(targetFrameworkDependencies).ToList();

            if (string.Equals(_projectReference?.Name, libraryRange.Name, StringComparison.OrdinalIgnoreCase))
            {
                dependencies.AddRange(_projectReference.ExternalProjectReferences
                                      .Select(reference => new LibraryDependency
                {
                    LibraryRange = new LibraryRange
                    {
                        Name           = reference,
                        VersionRange   = VersionRange.All,
                        TypeConstraint = LibraryTypes.ExternalProject
                    }
                }));
            }

            // Mark the library as unresolved if there were specified frameworks
            // and none of them resolved
            var unresolved = targetFrameworkInfo.FrameworkName == null &&
                             packageSpec.TargetFrameworks.Any();

            var library = new Library
            {
                LibraryRange = libraryRange,
                Identity     = new LibraryIdentity
                {
                    Name    = packageSpec.Name,
                    Version = packageSpec.Version,
                    Type    = LibraryTypes.Project,
                },
                Path         = packageSpec.FilePath,
                Dependencies = dependencies,
                Resolved     = !unresolved,
                [KnownLibraryProperties.PackageSpec] = packageSpec
            };

            return(library);
        }