示例#1
0
        private static LockFileLibrary ReadLibrary(string property, JToken json)
        {
            var library = new LockFileLibrary();
            var parts   = property.Split(new[] { '/' }, 2);

            library.Name = parts[0];
            if (parts.Length == 2)
            {
                library.Version = NuGetVersion.Parse(parts[1]);
            }

            library.Type = ReadString(json[TypeProperty]);

            var jObject = json as JObject;

            library.Path           = JsonUtility.ReadProperty <string>(jObject, PathProperty);
            library.MSBuildProject = JsonUtility.ReadProperty <string>(jObject, MSBuildProjectProperty);
            library.Sha512         = JsonUtility.ReadProperty <string>(jObject, Sha512Property);

            library.IsServiceable = ReadBool(json, ServicableProperty, defaultValue: false);
            library.Files         = ReadPathArray(json[FilesProperty] as JArray, ReadString);

            library.HasTools = ReadBool(json, HasToolsProperty, defaultValue: false);
            return(library);
        }
示例#2
0
        private static JProperty WriteLibrary(LockFileLibrary library)
        {
            var json = new JObject();

            if (library.IsServiceable)
            {
                WriteBool(json, ServicableProperty, library.IsServiceable);
            }

            if (library.Sha512 != null)
            {
                json[Sha512Property] = WriteString(library.Sha512);
            }

            json[TypeProperty] = WriteString(library.Type);

            if (library.Path != null)
            {
                json[PathProperty] = WriteString(library.Path);
            }

            if (library.MSBuildProject != null)
            {
                json[MSBuildProjectProperty] = WriteString(library.MSBuildProject);
            }

            WritePathArray(json, FilesProperty, library.Files, WriteString);
            return(new JProperty(
                       library.Name + "/" + library.Version.ToNormalizedString(),
                       json));
        }
示例#3
0
        private static JProperty WriteLibrary(LockFileLibrary library)
        {
            var json = new JObject();

            json["sha"] = WriteString(library.Sha);
            WriteObject(json, "frameworks", library.FrameworkGroups, WriteFrameworkGroup);
            WriteArray(json, "files", library.Files, WriteString);
            return(new JProperty(
                       library.Name + "/" + library.Version.ToString(),
                       json));
        }
        private JProperty WriteLibrary(LockFileLibrary library)
        {
            var json = new JObject();

            WriteObject(json, "dependencySets", library.DependencyGroups, WritePackageDependencySet);
            WriteFrameworkAssemblies(json, "frameworkAssemblies", library.FrameworkReferenceGroups);
            WriteArray(json, "packageAssemblyReferences", library.ReferenceGroups, WritePackageReferenceSet);
            json["contents"] = WriteObject(library.Files, WritePackageFile);
            return(new JProperty(
                       library.Name + "/" + library.Version.ToString(),
                       json));
        }
示例#5
0
        private JProperty WriteLibrary(LockFileLibrary library)
        {
            var json = new JObject();

            if (library.IsServiceable)
            {
                WriteBool(json, ServicableProperty, library.IsServiceable);
            }
            json[Sha512Property] = WriteString(library.Sha512);
            WritePathArray(json, FilesProperty, library.Files, WriteString);
            return(new JProperty(
                       library.Name + "/" + library.Version.ToString(),
                       json));
        }
示例#6
0
        private static LockFileLibrary ReadLibrary(string property, JToken json)
        {
            var library = new LockFileLibrary();
            var parts   = property.Split(new[] { '/' }, 2);

            library.Name = parts[0];
            if (parts.Length == 2)
            {
                library.Version = NuGetVersion.Parse(parts[1]);
            }
            library.Sha             = ReadString(json["sha"]);
            library.FrameworkGroups = ReadObject(json["frameworks"] as JObject, ReadFrameworkGroup);
            library.Files           = ReadArray(json["files"] as JArray, ReadString);
            return(library);;
        }
示例#7
0
        private LockFileLibrary ReadLibrary(string property, JToken json)
        {
            var library = new LockFileLibrary();
            var parts   = property.Split(new[] { '/' }, 2);

            library.Name = parts[0];
            if (parts.Length == 2)
            {
                library.Version = NuGetVersion.Parse(parts[1]);
            }
            library.IsServiceable = ReadBool(json, ServicableProperty, defaultValue: false);
            library.Sha512        = ReadString(json[Sha512Property]);
            library.Files         = ReadPathArray(json[FilesProperty] as JArray, ReadString);
            return(library);
        }
        private LockFileLibrary ReadLibrary(string property, JToken json)
        {
            var library = new LockFileLibrary();
            var parts   = property.Split(new[] { '/' }, 2);

            library.Name = parts[0];
            if (parts.Length == 2)
            {
                library.Version = NuGetVersion.Parse(parts[1]);
            }
            library.DependencyGroups         = ReadObject(json["dependencySets"] as JObject, ReadPackageDependencySet);
            library.FrameworkReferenceGroups = ReadFrameworkAssemblies(json["frameworkAssemblies"] as JObject);
            library.ReferenceGroups          = ReadArray(json["packageAssemblyReferences"] as JArray, ReadPackageReferenceSet);
            library.Files = ReadObject(json["contents"] as JObject, ReadPackageFile);
            return(library);
        }
示例#9
0
        private static void WriteLibrary(JsonWriter writer, LockFileLibrary library)
        {
            writer.WritePropertyName(library.Name + "/" + library.Version.ToNormalizedString());

            writer.WriteStartObject();

            if (library.IsServiceable)
            {
                writer.WritePropertyName(ServicableProperty);
                writer.WriteValue(library.IsServiceable);
            }

            if (library.Sha512 != null)
            {
                writer.WritePropertyName(Sha512Property);
                writer.WriteValue(library.Sha512);
            }

            writer.WritePropertyName(TypeProperty);
            writer.WriteValue(library.Type);

            if (library.Path != null)
            {
                writer.WritePropertyName(PathProperty);
                writer.WriteValue(library.Path);
            }

            if (library.MSBuildProject != null)
            {
                writer.WritePropertyName(MSBuildProjectProperty);
                writer.WriteValue(library.MSBuildProject);
            }

            if (library.HasTools)
            {
                writer.WritePropertyName(HasToolsProperty);
                writer.WriteValue(library.HasTools);
            }

            WritePathArray(writer, FilesProperty, library.Files);

            writer.WriteEndObject();
        }
示例#10
0
        private LockFileLibrary CreateLockFileLibrary(LocalPackageInfo package, SHA512 sha512, string correctedPackageName)
        {
            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 = File.OpenRead(package.ZipPath))
            {
                lockFileLib.Sha512 = Convert.ToBase64String(sha512.ComputeHash(nupkgStream));
                nupkgStream.Seek(0, SeekOrigin.Begin);

                var packageReader = new PackageReader(nupkgStream);

                // Get package files, excluding directory entries
                lockFileLib.Files = packageReader.GetFiles().Where(x => !x.EndsWith("/")).ToList();
            }

            return lockFileLib;
        }