public static PackageReferenceNode ToNode(this LockFileTargetLibrary library)
        {
            if (!library.IsPackage())
            {
                throw new ArgumentException(nameof(library));
            }

            return(new PackageReferenceNode(library.Name, library.Version.ToNormalizedString()));
        }
Beispiel #2
0
        private Library GetLibrary(
            LockFileTargetLibrary export,
            LockFileLookup libraryLookup,
            IDictionary <string, Dependency> dependencyLookup,
            bool runtime)
        {
            var  type      = export.Type;
            bool isPackage = export.IsPackage();

            // TEMPORARY: All packages are serviceable in RC2
            // See https://github.com/dotnet/cli/issues/2569
            var serviceable         = isPackage;
            var libraryDependencies = new HashSet <Dependency>();

            foreach (PackageDependency libraryDependency in export.Dependencies)
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string            hash     = string.Empty;
            string            path     = null;
            string            hashPath = null;
            LockFileLibrary   library;
            SingleProjectInfo referenceProjectInfo = null;

            if (libraryLookup.TryGetLibrary(export, out library))
            {
                if (isPackage)
                {
                    if (!string.IsNullOrEmpty(library.Sha512))
                    {
                        hash     = "sha512-" + library.Sha512;
                        hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version);
                    }

                    path = library.Path;
                }
                else if (export.IsProject())
                {
                    referenceProjectInfo = GetProjectInfo(library);

                    if (referenceProjectInfo is UnreferencedProjectInfo)
                    {
                        // unreferenced ProjectInfos will be added later as simple dll dependencies
                        return(null);
                    }

                    if (runtime)
                    {
                        // DependencyReferences do not get passed to the compilation, so we should only
                        // process them when getting the runtime libraries.

                        foreach (var dependencyReference in referenceProjectInfo.DependencyReferences)
                        {
                            libraryDependencies.Add(
                                new Dependency(
                                    GetReferenceLibraryName(dependencyReference),
                                    dependencyReference.Version));
                        }
                    }
                }
            }

            if (runtime)
            {
                return(CreateRuntimeLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           CreateRuntimeAssemblyGroups(export, referenceProjectInfo),
                           CreateNativeLibraryGroups(export),
                           CreateResourceAssemblyGroups(export, referenceProjectInfo),
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
            else
            {
                IEnumerable <string> assemblies = GetCompileTimeAssemblies(export, referenceProjectInfo);

                return(new CompilationLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           assemblies,
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
        }
        private Library GetLibrary(
            LockFileTargetLibrary export,
            LockFileLookup libraryLookup,
            IDictionary <string, Dependency> dependencyLookup,
            bool runtime)
        {
            var  type      = export.Type;
            bool isPackage = export.IsPackage();

            // TEMPORARY: All packages are serviceable in RC2
            // See https://github.com/dotnet/cli/issues/2569
            var serviceable         = isPackage;
            var libraryDependencies = new HashSet <Dependency>();

            foreach (PackageDependency libraryDependency in export.Dependencies)
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string            hash     = string.Empty;
            string            path     = null;
            string            hashPath = null;
            LockFileLibrary   library;
            SingleProjectInfo referenceProjectInfo = null;

            if (libraryLookup.TryGetLibrary(export, out library))
            {
                if (isPackage)
                {
                    if (!string.IsNullOrEmpty(library.Sha512))
                    {
                        hash     = "sha512-" + library.Sha512;
                        hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version);
                    }

                    path = library.Path;
                }
                else if (export.IsProject())
                {
                    referenceProjectInfo = GetProjectInfo(library);

                    if (referenceProjectInfo is UnreferencedProjectInfo)
                    {
                        // unreferenced ProjectInfos will be added later as simple dll dependencies
                        return(null);
                    }

                    if (runtime)
                    {
                        // DependencyReferences do not get passed to the compilation, so we should only
                        // process them when getting the runtime libraries.

                        foreach (var dependencyReference in referenceProjectInfo.DependencyReferences)
                        {
                            libraryDependencies.Add(
                                new Dependency(
                                    GetReferenceLibraryName(dependencyReference),
                                    dependencyReference.Version));
                        }
                    }
                }
            }

            if (runtime)
            {
                return(CreateRuntimeLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           CreateRuntimeAssemblyGroups(export, referenceProjectInfo),
                           CreateNativeLibraryGroups(export),
                           CreateResourceAssemblyGroups(export, referenceProjectInfo),
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
            else
            {
                IEnumerable <string> assemblies = Enumerable.Empty <string>();

                //  In some situations, the assets file will include compilation assets under the RID-specific
                //  target, but not under the RID-less target.  The RID-less target is what is used for project
                //  compilation, so make sure we get those assets when writing the compile references to the assets
                //  file.
                //  This can happen when the runtime graph adds dependencies which don't have compile assets excluded.
                //  This was encountered with the 4.3.0 System.Security.Claims, System.Security.Principal.Windows, and
                //  System.Threading.Overlapped packages.
                LockFileTargetLibrary exportWithCompileAssets;
                if (_compilationTargetLibraries != null)
                {
                    _compilationTargetLibraries.TryGetValue(export.Name, out exportWithCompileAssets);
                }
                else
                {
                    exportWithCompileAssets = export;
                }
                if (exportWithCompileAssets != null)
                {
                    assemblies = GetCompileTimeAssemblies(exportWithCompileAssets, referenceProjectInfo);
                }

                return(new CompilationLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           assemblies,
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
        }