private Item Resolve( Dictionary <LibraryRange, Item> resolvedItems, IEnumerable <IDependencyProvider> providers, LibraryRange packageKey, FrameworkName frameworkName) { Item item; if (resolvedItems.TryGetValue(packageKey, out item)) { return(item); } LibraryDescription match = null; foreach (var dependencyProvider in providers) { match = dependencyProvider.GetDescription(packageKey, frameworkName); if (match != null) { break; } } if (match == null) { resolvedItems[packageKey] = null; return(null); } if (resolvedItems.TryGetValue(match.Identity, out item)) { return(item); } item = new Item() { Description = match, Key = match.Identity, Dependencies = match.Dependencies }; resolvedItems[packageKey] = item; resolvedItems[match.Identity] = item; return(item); }
public LibraryDescription( LibraryRange requestedRange, LibraryIdentity identity, string path, string type, IEnumerable <LibraryDependency> dependencies, IEnumerable <string> assemblies, FrameworkName framework) { Path = path; RequestedRange = requestedRange; Identity = identity; Type = type; Dependencies = dependencies ?? Enumerable.Empty <LibraryDependency>(); Assemblies = assemblies ?? Enumerable.Empty <string>(); Framework = framework; }
public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkName targetFramework) { if (libraryRange.IsGacOrFrameworkReference) { return(null); } LockFileTargetLibrary targetLibrary = _lockFileLookup.GetTargetLibrary(targetFramework, libraryRange.Name); if (targetLibrary != null) { var package = _lockFileLookup.GetPackage(targetLibrary.Name, targetLibrary.Version); Debug.Assert(package != null); // If a NuGet dependency is supposed to provide assemblies but there is no assembly compatible with // current target framework, we should mark this dependency as unresolved var containsAssembly = package.Files .Any(x => x.StartsWith($"ref{Path.DirectorySeparatorChar}") || x.StartsWith($"lib{Path.DirectorySeparatorChar}")); var compatible = targetLibrary.FrameworkAssemblies.Any() || targetLibrary.CompileTimeAssemblies.Any() || targetLibrary.RuntimeAssemblies.Any() || !containsAssembly; var resolved = compatible; var packageDescription = new PackageDescription( libraryRange, package, targetLibrary, GetDependencies(targetLibrary), resolved, compatible); Initialize(packageDescription); return(packageDescription); } return(null); }
public ProjectDescription( LibraryRange libraryRange, Project project, IEnumerable <LibraryDependency> dependencies, IEnumerable <string> assemblies, FrameworkName framework, bool resolved) : base( libraryRange, new LibraryIdentity(project.Name, project.Version, isGacOrFrameworkReference: false), project.ProjectFilePath, LibraryTypes.Project, dependencies, assemblies, framework) { Project = project; Resolved = resolved; Compatible = resolved; }
public PackageDescription( LibraryRange requestedRange, LockFilePackageLibrary package, LockFileTargetLibrary lockFileLibrary, IEnumerable <LibraryDependency> dependencies, bool resolved, bool compatible) : base( requestedRange, new LibraryIdentity(package.Name, package.Version, isGacOrFrameworkReference: false), path: null, type: LibraryTypes.Package, dependencies: dependencies, assemblies: Enumerable.Empty <string>(), framework: null) { Library = package; Target = lockFileLibrary; Resolved = resolved; Compatible = compatible; }
public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkName targetFramework) { if (!libraryRange.IsGacOrFrameworkReference) { return(null); } if (!RuntimeEnvironmentHelper.IsWindows) { return(null); } if (!VersionUtility.IsDesktop(targetFramework)) { return(null); } var name = libraryRange.Name; var version = libraryRange.VersionRange?.MinVersion; string path; if (!TryResolvePartialName(libraryRange.GetReferenceAssemblyName(), version, out path)) { return(null); } _resolvedPaths[name] = path; return(new LibraryDescription( libraryRange, new LibraryIdentity(name, version, isGacOrFrameworkReference: true), path, LibraryTypes.GlobalAssemblyCache, Enumerable.Empty <LibraryDependency>(), new[] { libraryRange.GetReferenceAssemblyName() }, framework: null)); }
public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkName targetFramework) { if (libraryRange.IsGacOrFrameworkReference) { return(null); } string name = libraryRange.Name; Project project; // Can't find a project file with the name so bail if (!_projectResolver.TryResolveProject(name, out project)) { return(null); } // This never returns null var targetFrameworkInfo = project.GetTargetFramework(targetFramework); var targetFrameworkDependencies = new List <LibraryDependency>(targetFrameworkInfo.Dependencies); if (VersionUtility.IsDesktop(targetFramework)) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("mscorlib", frameworkReference: true) }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("System", frameworkReference: true) }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("System.Core", frameworkReference: true) }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("Microsoft.CSharp", frameworkReference: true) }); } var dependencies = project.Dependencies.Concat(targetFrameworkDependencies).ToList(); var loadableAssemblies = new List <string>(); if (project.IsLoadable) { loadableAssemblies.Add(project.Name); } // Mark the library as unresolved if there were specified frameworks // and none of them resolved bool unresolved = targetFrameworkInfo.FrameworkName == null && project.GetTargetFrameworks().Any(); return(new ProjectDescription( libraryRange, project, dependencies, loadableAssemblies, targetFrameworkInfo.FrameworkName, !unresolved)); }
public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkName targetFramework) { if (libraryRange.IsGacOrFrameworkReference) { return(null); } LockFileTargetLibrary targetLibrary = null; var versionRange = libraryRange.VersionRange; // REVIEW: This is a little messy because we have the lock file logic and non lock file logic in the same class // The runtime rewrite separates the 2 things. if (_lookup != null) { // This means we have a lock file and the target should have var lookupKey = Tuple.Create((string)null, targetFramework, libraryRange.Name); if (_lookup.TryGetValue(lookupKey, out targetLibrary)) { // Adjust the target version so we find the right one when looking at the // lock file libraries versionRange = new SemanticVersionRange(targetLibrary.Version); } } var package = FindCandidate(libraryRange.Name, versionRange); if (package != null) { IEnumerable <LibraryDependency> dependencies; var resolved = true; var compatible = true; if (package.LockFileLibrary != null) { if (targetLibrary?.Version == package.LockFileLibrary.Version) { dependencies = GetDependencies(package, targetFramework, targetLibrary); } else { resolved = false; dependencies = Enumerable.Empty <LibraryDependency>(); } // If a NuGet dependency is supposed to provide assemblies but there is no assembly compatible with // current target framework, we should mark this dependency as unresolved if (targetLibrary != null) { var containsAssembly = package.LockFileLibrary.Files .Any(x => x.StartsWith($"ref{Path.DirectorySeparatorChar}") || x.StartsWith($"lib{Path.DirectorySeparatorChar}")); compatible = targetLibrary.FrameworkAssemblies.Any() || targetLibrary.CompileTimeAssemblies.Any() || targetLibrary.RuntimeAssemblies.Any() || !containsAssembly; resolved = compatible; } } else { dependencies = GetDependencies(package, targetFramework, targetLibrary: null); } return(new PackageDescription( libraryRange, package, targetLibrary, dependencies, resolved, compatible)); } return(null); }