Пример #1
0
        private JProperty WriteFrameworkGroup(LockFileFrameworkGroup group)
        {
            var json = new JObject();

            json["dependencies"]        = WriteObject(group.Dependencies, WritePackageDependency);
            json["frameworkAssemblies"] = WriteArray(group.FrameworkAssemblies, WriteFrameworkAssemblyReference);
            json["runtimeAssemblies"]   = WritePathArray(group.RuntimeAssemblies, WriteString);
            json["compileAssemblies"]   = WritePathArray(group.CompileTimeAssemblies, WriteString);

            return(new JProperty(group.TargetFramework.FullName, json));
        }
Пример #2
0
        private LockFileFrameworkGroup ReadFrameworkGroup(string property, JToken json)
        {
            var group = new LockFileFrameworkGroup();

            group.TargetFramework       = new FrameworkName(property);
            group.Dependencies          = ReadObject(json["dependencies"] as JObject, ReadPackageDependency);
            group.FrameworkAssemblies   = ReadArray(json["frameworkAssemblies"] as JArray, ReadFrameworkAssemblyReference);
            group.RuntimeAssemblies     = ReadPathArray(json["runtimeAssemblies"] as JArray, ReadString);
            group.CompileTimeAssemblies = ReadPathArray(json["compileAssemblies"] as JArray, ReadString);

            return(group);
        }
Пример #3
0
        private IEnumerable<LibraryDependency> GetDependencies(PackageInfo packageInfo, FrameworkName targetFramework, LockFileFrameworkGroup lockFileGroup)
        {
            if (lockFileGroup != null)
            {
                foreach (var d in lockFileGroup.Dependencies)
                {
                    yield return new LibraryDependency
                    {
                        LibraryRange = new LibraryRange
                        {
                            Name = d.Id,
                            VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec)
                        }
                    };
                }

                foreach (var fa in lockFileGroup.FrameworkAssemblies)
                {
                    yield return new LibraryDependency
                    {
                        LibraryRange = new LibraryRange
                        {
                            Name = fa.AssemblyName,
                            IsGacOrFrameworkReference = 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.TryGetCompatibleItems(targetFramework, package.DependencySets, out dependencySet))
            {
                foreach (var set in dependencySet)
                {
                    foreach (var d in set.Dependencies)
                    {
                        yield return new LibraryDependency
                        {
                            LibraryRange = new LibraryRange
                            {
                                Name = d.Id,
                                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.TryGetCompatibleItems(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
                        {
                            Name = assemblyReference.AssemblyName,
                            IsGacOrFrameworkReference = true
                        }
                    };
                }
            }
        }
Пример #4
0
        public static LockFileLibrary CreateLockFileLibraryForProject(
            Runtime.Project project,
            IPackage package,
            SHA512 sha512,
            IEnumerable<FrameworkName> frameworks,
            IPackagePathResolver resolver,
            string correctedPackageName = null)
        {
            var lockFileLib = new LockFileLibrary();

            // 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;

            using (var nupkgStream = package.GetStream())
            {
                lockFileLib.Sha = Convert.ToBase64String(sha512.ComputeHash(nupkgStream));
            }
            lockFileLib.Files = package.GetFiles().Select(p => p.Path).ToList();

            foreach (var framework in frameworks)
            {
                var group = new LockFileFrameworkGroup();
                group.TargetFramework = framework;

                IEnumerable<PackageDependencySet> dependencySet;
                if (VersionUtility.TryGetCompatibleItems(framework, package.DependencySets, out dependencySet))
                {
                    var set = dependencySet.FirstOrDefault()?.Dependencies?.ToList();

                    if (set != null)
                    {
                        group.Dependencies = set;
                    }
                }

                // TODO: Remove this when we do #596
                // ASP.NET Core isn't compatible with generic PCL profiles
                if (!string.Equals(framework.Identifier, VersionUtility.AspNetCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(framework.Identifier, VersionUtility.DnxCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
                {
                    IEnumerable<FrameworkAssemblyReference> frameworkAssemblies;
                    if (VersionUtility.TryGetCompatibleItems(framework, package.FrameworkAssemblies, out 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;
                            }

                            group.FrameworkAssemblies.Add(assemblyReference);
                        }
                    }
                }

                group.RuntimeAssemblies = GetPackageAssemblies(package, framework);

                string contractPath = Path.Combine("lib", "contract", package.Id + ".dll");
                var hasContract = lockFileLib.Files.Any(path => path == contractPath);
                var hasLib = group.RuntimeAssemblies.Any();

                if (hasContract && hasLib && !VersionUtility.IsDesktop(framework))
                {
                    group.CompileTimeAssemblies.Add(contractPath);
                }
                else if (hasLib)
                {
                    group.CompileTimeAssemblies.AddRange(group.RuntimeAssemblies);
                }

                lockFileLib.FrameworkGroups.Add(group);
            }

            var installPath = resolver.GetInstallPath(package.Id, package.Version);
            foreach (var assembly in lockFileLib.FrameworkGroups.SelectMany(f => f.RuntimeAssemblies))
            {
                var assemblyPath = Path.Combine(installPath, assembly);
                if (IsAssemblyServiceable(assemblyPath))
                {
                    lockFileLib.IsServiceable = true;
                    break;
                }
            }

            return lockFileLib;
        }