private void Write(RuntimeModel.IObjectWriter writer)
        {
            writer.WriteNameValue("format", 1);

            writer.WriteObjectStart("restore");

            // Preserve default sort order
            foreach (var restoreName in _restore)
            {
                writer.WriteObjectStart(restoreName);
                writer.WriteObjectEnd();
            }

            writer.WriteObjectEnd();

            writer.WriteObjectStart("projects");

            // Preserve default sort order
            foreach (var pair in _projects)
            {
                var project = pair.Value;

                writer.WriteObjectStart(project.RestoreMetadata.ProjectUniqueName);
                PackageSpecWriter.Write(project, writer);
                writer.WriteObjectEnd();
            }

            writer.WriteObjectEnd();
        }
示例#2
0
        private static JObject WriteLockFile(LockFile lockFile)
        {
            var json = new JObject();

            json[VersionProperty]   = new JValue(lockFile.Version);
            json[TargetsProperty]   = WriteObject(lockFile.Targets, WriteTarget);
            json[LibrariesProperty] = WriteObject(lockFile.Libraries, WriteLibrary);
            json[ProjectFileDependencyGroupsProperty] = WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup);

            if (lockFile.PackageFolders?.Any() == true)
            {
                json[PackageFoldersProperty] = WriteObject(lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    var writer = new JsonObjectWriter();
                    PackageSpecWriter.Write(lockFile.PackageSpec, writer);
                    var packageSpec = writer.GetJObject();
                    json[PackageSpecProperty] = packageSpec;
                }
            }

            return(json);
        }
示例#3
0
        private static void WriteLockFile(JsonWriter writer, IObjectWriter jsonObjectWriter, LockFile lockFile)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(VersionProperty);
            writer.WriteValue(lockFile.Version);

            writer.WritePropertyName(TargetsProperty);
            JsonUtility.WriteObject(writer, lockFile.Targets, WriteTarget);

            writer.WritePropertyName(LibrariesProperty);
            JsonUtility.WriteObject(writer, lockFile.Libraries, WriteLibrary);

            writer.WritePropertyName(ProjectFileDependencyGroupsProperty);
            JsonUtility.WriteObject(writer, lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup);

            if (lockFile.PackageFolders?.Any() == true)
            {
                writer.WritePropertyName(PackageFoldersProperty);
                JsonUtility.WriteObject(writer, lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    writer.WritePropertyName(PackageSpecProperty);

                    jsonObjectWriter.WriteObjectStart();

                    PackageSpecWriter.Write(lockFile.PackageSpec, jsonObjectWriter);

                    jsonObjectWriter.WriteObjectEnd();
                }
            }

            if (lockFile.Version >= 3)
            {
                if (lockFile.LogMessages.Count > 0)
                {
                    var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath;
                    writer.WritePropertyName(LogsProperty);
                    WriteLogMessages(writer, lockFile.LogMessages, projectPath);
                }
            }

            if (lockFile.CentralTransitiveDependencyGroups.Any())
            {
                writer.WritePropertyName(CentralTransitiveDependencyGroupsProperty);
                WriteCentralTransitiveDependencyGroup(jsonObjectWriter, lockFile.CentralTransitiveDependencyGroups);
            }

            writer.WriteEndObject();
        }
示例#4
0
        private static JObject WriteLockFile(LockFile lockFile)
        {
            var json = new JObject
            {
                [VersionProperty]   = new JValue(lockFile.Version),
                [TargetsProperty]   = JsonUtility.WriteObject(lockFile.Targets, WriteTarget),
                [LibrariesProperty] = JsonUtility.WriteObject(lockFile.Libraries, WriteLibrary),
                [ProjectFileDependencyGroupsProperty] = JsonUtility.WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup)
            };

            if (lockFile.PackageFolders?.Any() == true)
            {
                json[PackageFoldersProperty] = JsonUtility.WriteObject(lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    using (var jsonWriter = new JTokenWriter())
                        using (var writer = new JsonObjectWriter(jsonWriter))
                        {
                            writer.WriteObjectStart();

                            PackageSpecWriter.Write(lockFile.PackageSpec, writer);

                            writer.WriteObjectEnd();

                            json[PackageSpecProperty] = (JObject)jsonWriter.Token;
                        }
                }
            }

            if (lockFile.Version >= 3)
            {
                if (lockFile.LogMessages.Count > 0)
                {
                    var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath;
                    json[LogsProperty] = WriteLogMessages(lockFile.LogMessages, projectPath);
                }
            }

            if (lockFile.CentralTransitiveDependencyGroups.Any())
            {
                JToken token = WriteCentralTransitiveDependencyGroup(lockFile.CentralTransitiveDependencyGroups);
                json[CentralTransitiveDependencyGroupsProperty] = (JObject)token;
            }

            return(json);
        }
示例#5
0
        /// <summary>
        /// Clone a PackageSpec and underlying JObject.
        /// </summary>
        public PackageSpec Clone()
        {
            var writer = new JsonObjectWriter();

            PackageSpecWriter.Write(this, writer);
            var json = writer.GetJObject();

            var spec = JsonPackageSpecReader.GetPackageSpec(json);

            spec.Name     = Name;
            spec.FilePath = FilePath;

            return(spec);
        }
示例#6
0
        private static JObject WriteLockFile(LockFile lockFile)
        {
            var json = new JObject
            {
                [VersionProperty]   = new JValue(lockFile.Version),
                [TargetsProperty]   = WriteObject(lockFile.Targets, WriteTarget),
                [LibrariesProperty] = WriteObject(lockFile.Libraries, WriteLibrary),
                [ProjectFileDependencyGroupsProperty] = WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup)
            };

            if (lockFile.PackageFolders?.Any() == true)
            {
                json[PackageFoldersProperty] = WriteObject(lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    var writer = new JsonObjectWriter();
                    PackageSpecWriter.Write(lockFile.PackageSpec, writer);
                    var packageSpec = writer.GetJObject();
                    json[PackageSpecProperty] = packageSpec;
                }
            }

            if (lockFile.Version >= 3)
            {
                if (lockFile.LogMessages.Count > 0)
                {
                    var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath;
                    json[LogsProperty] = WriteLogMessages(lockFile.LogMessages, projectPath);
                }
            }

            return(json);
        }