コード例 #1
0
        private void ResolveDependencies(Dictionary <LibraryKey, LibraryDescription> libraries,
                                         ReferenceAssemblyDependencyResolver referenceAssemblyDependencyResolver,
                                         out bool requiresFrameworkAssemblies)
        {
            requiresFrameworkAssemblies = false;

            foreach (var library in libraries.Values.ToList())
            {
                if (Equals(library.Identity.Type, LibraryType.Package) &&
                    !Directory.Exists(library.Path))
                {
                    // If the package path doesn't exist then mark this dependency as unresolved
                    library.Resolved = false;
                }

                library.Framework = library.Framework ?? TargetFramework;
                foreach (var dependency in library.Dependencies)
                {
                    var keyType = dependency.Target == LibraryType.ReferenceAssembly ? LibraryType.ReferenceAssembly : LibraryType.Unspecified;
                    var key     = new LibraryKey(dependency.Name, keyType);

                    LibraryDescription dep;
                    if (!libraries.TryGetValue(key, out dep))
                    {
                        if (Equals(LibraryType.ReferenceAssembly, dependency.Target))
                        {
                            requiresFrameworkAssemblies = true;

                            dep = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework) ??
                                  UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);

                            dep.Framework  = TargetFramework;
                            libraries[key] = dep;
                        }
                        else
                        {
                            dep            = UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);
                            libraries[key] = dep;
                        }
                    }

                    dep.RequestedRanges.Add(dependency);
                    dep.Parents.Add(library);
                }
            }
        }
コード例 #2
0
ファイル: ProjectContextBuilder.cs プロジェクト: nattress/cli
        private void ScanLibraries(LockFileTarget target, LockFileLookup lockFileLookup, Dictionary <LibraryKey, LibraryDescription> libraries, MSBuildDependencyProvider msbuildResolver, PackageDependencyProvider packageResolver, ProjectDependencyProvider projectResolver)
        {
            foreach (var library in target.Libraries)
            {
                LibraryDescription description = null;
                var type = LibraryType.Unspecified;

                if (string.Equals(library.Type, "project"))
                {
                    var projectLibrary = lockFileLookup.GetProject(library.Name);

                    if (projectLibrary != null)
                    {
                        if (MSBuildDependencyProvider.IsMSBuildProjectLibrary(projectLibrary))
                        {
                            description = msbuildResolver.GetDescription(TargetFramework, projectLibrary, library);
                            type        = LibraryType.MSBuildProject;
                        }
                        else
                        {
                            var path = Path.GetFullPath(Path.Combine(ProjectDirectory, projectLibrary.Path));
                            description = projectResolver.GetDescription(library.Name, path, library, ProjectResolver);
                            type        = LibraryType.Project;
                        }
                    }
                }
                else
                {
                    var packageEntry = lockFileLookup.GetPackage(library.Name, library.Version);

                    if (packageEntry != null)
                    {
                        description = packageResolver.GetDescription(TargetFramework, packageEntry, library);
                    }

                    type = LibraryType.Package;
                }

                description = description ?? UnresolvedDependencyProvider.GetDescription(new LibraryRange(library.Name, type), target.TargetFramework);

                libraries.Add(new LibraryKey(library.Name), description);
            }
        }
コード例 #3
0
        private void ResolveDependencies(Dictionary <LibraryKey, LibraryDescription> libraries,
                                         ReferenceAssemblyDependencyResolver referenceAssemblyDependencyResolver,
                                         out bool requiresFrameworkAssemblies)
        {
            // Remark: the LibraryType in the key of the given dictionary are all "Unspecified" at the beginning.
            requiresFrameworkAssemblies = false;

            foreach (var pair in libraries.ToList())
            {
                var library = pair.Value;

                if (Equals(library.Identity.Type, LibraryType.Package) &&
                    !Directory.Exists(library.Path))
                {
                    // If the package path doesn't exist then mark this dependency as unresolved
                    library.Resolved = false;
                }

                // The System.* packages provide placeholders on any non netstandard platform
                // To make them work seamlessly on those platforms, we fill the gap with a reference
                // assembly (if available)
                var package = library as PackageDescription;
                if (package != null && package.Resolved && !package.Target.CompileTimeAssemblies.Any())
                {
                    var replacement = referenceAssemblyDependencyResolver.GetDescription(new LibraryRange(library.Identity.Name, LibraryType.ReferenceAssembly), TargetFramework);
                    if (replacement?.Resolved == true)
                    {
                        requiresFrameworkAssemblies = true;

                        // Remove the original package reference
                        libraries.Remove(pair.Key);

                        // Insert a reference assembly key if there isn't one
                        var key = new LibraryKey(replacement.Identity.Name, LibraryType.ReferenceAssembly);
                        if (!libraries.ContainsKey(key))
                        {
                            libraries[key] = replacement;
                        }
                    }
                }
            }

            foreach (var pair in libraries.ToList())
            {
                var library = pair.Value;
                library.Framework = library.Framework ?? TargetFramework;
                foreach (var dependency in library.Dependencies)
                {
                    var keyType = dependency.Target == LibraryType.ReferenceAssembly ?
                                  LibraryType.ReferenceAssembly :
                                  LibraryType.Unspecified;

                    var key = new LibraryKey(dependency.Name, keyType);

                    LibraryDescription dependencyDescription;
                    if (!libraries.TryGetValue(key, out dependencyDescription))
                    {
                        if (keyType == LibraryType.ReferenceAssembly)
                        {
                            // a dependency is specified to be reference assembly but fail to match
                            // then add a unresolved dependency
                            dependencyDescription = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework) ??
                                                    UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);
                            libraries[key] = dependencyDescription;
                        }
                        else if (!libraries.TryGetValue(new LibraryKey(dependency.Name, LibraryType.ReferenceAssembly), out dependencyDescription))
                        {
                            // a dependency which type is unspecified fails to match, then try to find a
                            // reference assembly type dependency
                            dependencyDescription = UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);
                            libraries[key]        = dependencyDescription;
                        }
                    }

                    dependencyDescription.RequestedRanges.Add(dependency);
                    dependencyDescription.Parents.Add(library);
                }
            }
        }
コード例 #4
0
        private void ResolveDependencies(Dictionary <LibraryKey, LibraryDescription> libraries,
                                         ReferenceAssemblyDependencyResolver referenceAssemblyDependencyResolver,
                                         out bool requiresFrameworkAssemblies)
        {
            // Remark: the LibraryType in the key of the given dictionary are all "Unspecified" at the beginning.
            requiresFrameworkAssemblies = false;

            foreach (var pair in libraries.ToList())
            {
                var library = pair.Value;

                // The System.* packages provide placeholders on any non netstandard platform
                // To make them work seamlessly on those platforms, we fill the gap with a reference
                // assembly (if available)
                var package = library as PackageDescription;
                if (package != null &&
                    package.Resolved &&
                    package.HasCompileTimePlaceholder &&
                    !TargetFramework.IsPackageBased)
                {
                    // requiresFrameworkAssemblies is true whenever we find a CompileTimePlaceholder in a non-package based framework, even if
                    // the reference is unresolved. This ensures the best error experience when someone is building on a machine without
                    // the target framework installed.
                    requiresFrameworkAssemblies = true;

                    var newKey     = new LibraryKey(library.Identity.Name, LibraryType.ReferenceAssembly);
                    var dependency = new LibraryRange(library.Identity.Name, LibraryType.ReferenceAssembly);

                    var replacement = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework);

                    // If the reference is unresolved, just skip it.  Don't replace the package dependency
                    if (replacement == null)
                    {
                        continue;
                    }

                    // Remove the original package reference
                    libraries.Remove(pair.Key);

                    // Insert a reference assembly key if there isn't one
                    if (!libraries.ContainsKey(newKey))
                    {
                        libraries[newKey] = replacement;
                    }
                }
            }

            foreach (var pair in libraries.ToList())
            {
                var library = pair.Value;
                library.Framework = library.Framework ?? TargetFramework;
                foreach (var dependency in library.Dependencies)
                {
                    var keyType = dependency.Target == LibraryType.ReferenceAssembly ?
                                  LibraryType.ReferenceAssembly :
                                  LibraryType.Unspecified;

                    var key = new LibraryKey(dependency.Name, keyType);

                    LibraryDescription dependencyDescription;
                    if (!libraries.TryGetValue(key, out dependencyDescription))
                    {
                        if (keyType == LibraryType.ReferenceAssembly)
                        {
                            // a dependency is specified to be reference assembly but fail to match
                            // then add a unresolved dependency
                            dependencyDescription = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework) ??
                                                    UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);
                            libraries[key] = dependencyDescription;
                        }
                        else if (!libraries.TryGetValue(new LibraryKey(dependency.Name, LibraryType.ReferenceAssembly), out dependencyDescription))
                        {
                            // a dependency which type is unspecified fails to match, then try to find a
                            // reference assembly type dependency
                            dependencyDescription = UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework);
                            libraries[key]        = dependencyDescription;
                        }
                    }

                    dependencyDescription.RequestedRanges.Add(dependency);
                    dependencyDescription.Parents.Add(library);
                }
            }

            // Deduplicate libraries with the same name
            // Priority list is backwards so not found -1 would be last when sorting by descending
            var priorities = new[] { LibraryType.Package, LibraryType.Project, LibraryType.ReferenceAssembly };
            var nameGroups = libraries.Keys.ToLookup(libraryKey => libraryKey.Name);

            foreach (var nameGroup in nameGroups)
            {
                var librariesToRemove = nameGroup
                                        .OrderByDescending(libraryKey => Array.IndexOf(priorities, libraryKey.LibraryType))
                                        .Skip(1);

                foreach (var library in librariesToRemove)
                {
                    libraries.Remove(library);
                }
            }
        }