public ProjectDescription GetDescription(string name, string path, LockFileTargetLibrary targetLibrary) { Project project; // Can't find a project file with the name so bail if (!Project.TryGetProject(path, out project)) { return new ProjectDescription(name, path); } return GetDescription(targetLibrary.TargetFramework, project); }
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 PackageDescription( LibraryRange requestedRange, PackageInfo package, LockFileTargetLibrary lockFileLibrary, IEnumerable<LibraryDependency> dependencies, bool resolved, bool compatible) : base(requestedRange, new LibraryIdentity(package.Id, package.Version, isGacOrFrameworkReference: false), path: null, type: LibraryTypes.Package, dependencies: dependencies, assemblies: Enumerable.Empty<string>(), framework: null) { Package = package; LockFileLibrary = lockFileLibrary; Resolved = resolved; Compatible = compatible; }
private void PopulateDependencies(List <LibraryDependency> dependencies, LockFileTargetLibrary targetLibrary) { foreach (var d in targetLibrary.Dependencies) { dependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange(d.Id, frameworkReference: false) { VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec) } }); } foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies) { dependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange(frameworkAssembly, frameworkReference: true) }); } }
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; }
private IEnumerable <LibraryDependency> GetDependencies(LockFileTargetLibrary targetLibrary) { foreach (var d in targetLibrary.Dependencies) { yield return(new LibraryDependency { LibraryRange = new LibraryRange(d.Id, frameworkReference: false) { VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec) } }); } foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies) { yield return(new LibraryDependency { LibraryRange = new LibraryRange(frameworkAssembly, frameworkReference: true) }); } }
private LockFileTargetLibrary ReadTargetLibrary(string property, JsonValue json) { var jobject = json as JsonObject; if (jobject == null) { throw FileFormatException.Create("The value type is not an object.", json); } var library = new LockFileTargetLibrary(); var parts = property.Split(new[] { '/' }, 2); library.Name = parts[0]; if (parts.Length == 2) { library.Version = SemanticVersion.Parse(parts[1]); } library.Type = jobject.ValueAsString("type"); var framework = jobject.ValueAsString("framework"); if (framework != null) { library.TargetFramework = new FrameworkName(framework); } library.Dependencies = ReadObject(jobject.ValueAsJsonObject("dependencies"), ReadPackageDependency); library.FrameworkAssemblies = new HashSet <string>(ReadArray(jobject.Value("frameworkAssemblies"), ReadFrameworkAssemblyReference), StringComparer.OrdinalIgnoreCase); library.RuntimeAssemblies = ReadObject(jobject.ValueAsJsonObject("runtime"), ReadFileItem); library.CompileTimeAssemblies = ReadObject(jobject.ValueAsJsonObject("compile"), ReadFileItem); library.ResourceAssemblies = ReadObject(jobject.ValueAsJsonObject("resource"), ReadFileItem); library.NativeLibraries = ReadObject(jobject.ValueAsJsonObject("native"), ReadFileItem); return(library); }
public static LockFileTargetLibrary CreateLockFileTargetLibrary(Runtime.Project projectDependency, RestoreContext context) { var targetFrameworkInfo = projectDependency.GetCompatibleTargetFramework(context.FrameworkName); var lockFileLib = new LockFileTargetLibrary { Name = projectDependency.Name, Version = projectDependency.Version, TargetFramework = targetFrameworkInfo.FrameworkName, // null TFM means it's incompatible Type = "project" }; var dependencies = projectDependency.Dependencies.Concat(targetFrameworkInfo.Dependencies); foreach (var dependency in dependencies) { if (dependency.LibraryRange.IsGacOrFrameworkReference) { lockFileLib.FrameworkAssemblies.Add( LibraryRange.GetAssemblyName(dependency.LibraryRange.Name)); } else { lockFileLib.Dependencies.Add(new PackageDependency( dependency.LibraryRange.Name, dependency.LibraryRange.VersionRange)); } } return lockFileLib; }
private static void AddFrameworkReferences(LockFileTargetLibrary lockFileLib, FrameworkName framework, IEnumerable<FrameworkAssemblyReference> frameworkAssemblies) { foreach (var assemblyReference in frameworkAssemblies) { if (!assemblyReference.SupportedFrameworks.Any() && !VersionUtility.IsDesktop(framework)) { // REVIEW: This isn't 100% correct since none *can* mean // any in theory, but in practice it means .NET full reference assembly // If there's no supported target frameworks and we're not targeting // the desktop framework then skip it. // To do this properly we'll need all reference assemblies supported // by each supported target framework which isn't always available. continue; } lockFileLib.FrameworkAssemblies.Add(assemblyReference.AssemblyName); } }
public static LockFileTargetLibrary CreateLockFileTargetLibrary(LockFilePackageLibrary library, IPackage package, RestoreContext context, string correctedPackageName) { var lockFileLib = new LockFileTargetLibrary { Type = "package" }; var framework = context.FrameworkName; var runtimeIdentifier = context.RuntimeName; // package.Id is read from nuspec and it might be in wrong casing. // correctedPackageName should be the package name used by dependency graph and // it has the correct casing that runtime needs during dependency resolution. lockFileLib.Name = correctedPackageName ?? package.Id; lockFileLib.Version = package.Version; var files = library.Files.Select(p => p.Replace(Path.DirectorySeparatorChar, '/')); var contentItems = new ContentItemCollection(); contentItems.Load(files); IEnumerable<PackageDependencySet> dependencySet; if (VersionUtility.GetNearest(framework, package.DependencySets, out dependencySet)) { var set = dependencySet.FirstOrDefault()?.Dependencies?.ToList(); if (set != null) { lockFileLib.Dependencies = set; } } // TODO: Remove this when we do #596 // ASP.NET Core and .NET Core 5.0 don't have framework reference assemblies if (!VersionUtility.IsPackageBased(framework)) { IEnumerable<FrameworkAssemblyReference> frameworkAssemblies; if (VersionUtility.GetNearest(framework, package.FrameworkAssemblies, out frameworkAssemblies)) { AddFrameworkReferences(lockFileLib, framework, frameworkAssemblies); } // Add framework assemblies with empty supported frameworks AddFrameworkReferences(lockFileLib, framework, package.FrameworkAssemblies.Where(f => !f.SupportedFrameworks.Any())); } var patterns = PatternDefinitions.DotNetPatterns; var criteriaBuilderWithTfm = new SelectionCriteriaBuilder(patterns.Properties.Definitions); var criteriaBuilderWithoutTfm = new SelectionCriteriaBuilder(patterns.Properties.Definitions); if (context.AllRuntimeNames != null) { foreach (var runtimeName in context.AllRuntimeNames) { criteriaBuilderWithTfm = criteriaBuilderWithTfm .Add["tfm", framework]["rid", runtimeName]; criteriaBuilderWithoutTfm = criteriaBuilderWithoutTfm .Add["rid", runtimeName]; } } criteriaBuilderWithTfm = criteriaBuilderWithTfm .Add["tfm", framework]; var criteria = criteriaBuilderWithTfm.Criteria; var compileGroup = contentItems.FindBestItemGroup(criteria, patterns.CompileTimeAssemblies, patterns.ManagedAssemblies); if (compileGroup != null) { lockFileLib.CompileTimeAssemblies = compileGroup.Items.Select(t => (LockFileItem)t.Path).ToList(); } var runtimeGroup = contentItems.FindBestItemGroup(criteria, patterns.ManagedAssemblies); if (runtimeGroup != null) { lockFileLib.RuntimeAssemblies = runtimeGroup.Items.Select(p => (LockFileItem)p.Path).ToList(); } var resourceGroup = contentItems.FindBestItemGroup(criteria, patterns.ResourceAssemblies); if (resourceGroup != null) { lockFileLib.ResourceAssemblies = resourceGroup.Items.Select(ToResourceLockFileItem).ToList(); } var nativeGroup = contentItems.FindBestItemGroup(criteriaBuilderWithoutTfm.Criteria, patterns.NativeLibraries); if (nativeGroup != null) { lockFileLib.NativeLibraries = nativeGroup.Items.Select(p => (LockFileItem)p.Path).ToList(); } // COMPAT: Support lib/contract so older packages can be consumed string contractPath = "lib/contract/" + package.Id + ".dll"; var hasContract = files.Any(path => path == contractPath); var hasLib = lockFileLib.RuntimeAssemblies.Any(); if (hasContract && hasLib && !VersionUtility.IsDesktop(framework)) { lockFileLib.CompileTimeAssemblies.Clear(); lockFileLib.CompileTimeAssemblies.Add(contractPath); } // See if there's a list of specific references defined for this target framework IEnumerable<PackageReferenceSet> referenceSets; if (VersionUtility.GetNearest(framework, package.PackageAssemblyReferences, out referenceSets)) { // Get the first compatible reference set var referenceSet = referenceSets.FirstOrDefault(); if (referenceSet != null) { // Remove all compile-time assemblies of which names do not appear in the References list lockFileLib.CompileTimeAssemblies.RemoveAll(path => path.Path.StartsWith("lib/") && !referenceSet.References.Contains(Path.GetFileName(path), StringComparer.OrdinalIgnoreCase)); } } return lockFileLib; }
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); }
private IEnumerable <LibraryDependency> GetDependencies(PackageInfo packageInfo, FrameworkName targetFramework, LockFileTargetLibrary targetLibrary) { if (targetLibrary != null) { foreach (var d in targetLibrary.Dependencies) { yield return(new LibraryDependency { LibraryRange = new LibraryRange(d.Id, frameworkReference: false) { VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec) } }); } foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies) { yield return(new LibraryDependency { LibraryRange = new LibraryRange(frameworkAssembly, frameworkReference: true) }); } yield break; } // If we weren't given a lockFileGroup, there isn't a lock file, so resolve the NuGet way. var package = packageInfo.Package; IEnumerable <PackageDependencySet> dependencySet; if (VersionUtility.GetNearest(targetFramework, package.DependencySets, out dependencySet)) { foreach (var set in dependencySet) { foreach (var d in set.Dependencies) { yield return(new LibraryDependency { LibraryRange = new LibraryRange(d.Id, frameworkReference: false) { VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec) }, }); } } } // TODO: Remove this when we do #596 // ASP.NET Core isn't compatible with generic PCL profiles if (string.Equals(targetFramework.Identifier, VersionUtility.AspNetCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) || string.Equals(targetFramework.Identifier, VersionUtility.DnxCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase)) { yield break; } IEnumerable <FrameworkAssemblyReference> frameworkAssemblies; if (VersionUtility.GetNearest(targetFramework, package.FrameworkAssemblies, out frameworkAssemblies)) { foreach (var assemblyReference in frameworkAssemblies) { if (!assemblyReference.SupportedFrameworks.Any() && !VersionUtility.IsDesktop(targetFramework)) { // REVIEW: This isn't 100% correct since none *can* mean // any in theory, but in practice it means .NET full reference assembly // If there's no supported target frameworks and we're not targeting // the desktop framework then skip it. // To do this properly we'll need all reference assemblies supported // by each supported target framework which isn't always available. continue; } yield return(new LibraryDependency { LibraryRange = new LibraryRange(assemblyReference.AssemblyName, frameworkReference: true) }); } } }