コード例 #1
0
        private static SolutionConfigurationPlatformsGlobalSection DeserializeSolutionConfigurationPlatformsGlobalSection(TextReader reader, ref string currentLine, PreOrPostSolution preOrPostSolution)
        {
            var solutionConfigurationPlatformsGlobalSection = new SolutionConfigurationPlatformsGlobalSection
            {
                Name = SolutionConfigurationPlatformsGlobalSection.SolutionFileGlobalSectionName,
                PreOrPostSolution = preOrPostSolution
            };

            currentLine = reader.ReadLine().Trim();

            while (!SolutionFileTextSerializer.GlobalSectionEndRegex.IsMatch(currentLine))
            {
                var assignmentTokens = currentLine.Split("=");

                var targetToken = assignmentTokens[0].Trim();
                var valueToken  = assignmentTokens[1].Trim();

                var solutionBuildConfiguration       = SolutionFileTextSerializer.DeserializeSolutionBuildConfiguration(targetToken);
                var mappedSolutionBuildConfiguration = SolutionFileTextSerializer.DeserializeSolutionBuildConfiguration(valueToken);

                var solutionBuildConfigurationMapping = new SolutionBuildConfigurationMapping
                {
                    SolutionBuildConfiguration       = solutionBuildConfiguration,
                    MappedSolutionBuildConfiguration = mappedSolutionBuildConfiguration,
                };

                solutionConfigurationPlatformsGlobalSection.SolutionBuildConfigurationMappings.Add(solutionBuildConfigurationMapping);

                currentLine = reader.ReadLine().Trim();
            }

            return(solutionConfigurationPlatformsGlobalSection);
        }
        public static void Serialize(string solutionFilePath, SolutionFile obj, bool overwrite = true)
        {
            using (var fileStream = FileStreamHelper.NewWrite(solutionFilePath, overwrite))
                using (var textWriter = StreamWriterHelper.NewLeaveOpenAddBOM(fileStream))
                {
                    var solutionFileTextSerialializer = new SolutionFileTextSerializer();

                    solutionFileTextSerialializer.Serialize(textWriter, obj);
                }
        }
        public static SolutionFile Deserialize(string solutionFilePath)
        {
            using (var fileStream = FileStreamHelper.NewRead(solutionFilePath))
                using (var textReader = StreamReaderHelper.NewLeaveOpen(fileStream))
                {
                    var solutionFileTextSerialializer = new SolutionFileTextSerializer();

                    var solutionFile = solutionFileTextSerialializer.Deserialize(textReader);
                    return(solutionFile);
                }
        }
コード例 #4
0
        public SolutionFile Deserialize(TextReader reader)
        {
            var solutionFile = new SolutionFile();

            var blankBeginLine       = reader.ReadLine();
            var formatVersionLine    = reader.ReadLine();
            var monikerLine          = reader.ReadLine();
            var vsVersionLine        = reader.ReadLine();
            var vsMinimumVersionLine = reader.ReadLine();

            var formatVersionTokens = formatVersionLine.Split(' ');
            var formatVersionToken  = formatVersionTokens.Last();

            solutionFile.FormatVersion = Version.Parse(formatVersionToken);

            solutionFile.VisualStudioMoniker = monikerLine;

            var vsVersionTokens = vsVersionLine.Split(' ');
            var vsVersionToken  = vsVersionTokens.Last();

            solutionFile.VisualStudioVersion = Version.Parse(vsVersionToken);

            var vsMinimumVersionTokens = vsMinimumVersionLine.Split(' ');
            var vsMinimumVersionToken  = vsMinimumVersionTokens.Last();

            solutionFile.MinimumVisualStudioVersion = Version.Parse(vsMinimumVersionToken);

            var currentLine = reader.ReadLine();

            if (SolutionFileTextSerializer.ProjectLineRegex.IsMatch(currentLine))
            {
                SolutionFileTextSerializer.DeserializeProjects(reader, ref currentLine, solutionFile);
            }

            if (!SolutionFileTextSerializer.GlobalLineRegex.IsMatch(currentLine))
            {
                throw new Exception($"Unknown line.\nExpected: \"Global\".\nFound: {currentLine}");
            }

            SolutionFileTextSerializer.DeserializeGlobals(reader, ref currentLine, solutionFile);

            var blankEndLine = reader.ReadLine();

            if (reader.ReadToEnd() != String.Empty)
            {
                throw new Exception("Reader was not at end.");
            }

            return(solutionFile);
        }
コード例 #5
0
        private static void DeserializeProjects(TextReader reader, ref string currentLine, SolutionFile solutionFile)
        {
            if (!SolutionFileTextSerializer.ProjectLineRegex.IsMatch(currentLine))
            {
                throw new Exception($"Unknown line.\nExpected: \"Project...\".\nFound: {currentLine}");
            }

            while (!SolutionFileTextSerializer.GlobalLineRegex.IsMatch(currentLine))
            {
                SolutionFileTextSerializer.DeserializeProject(reader, ref currentLine, solutionFile);

                currentLine = reader.ReadLine();
            }
        }
コード例 #6
0
        private static ProjectConfigurationPlatformsGlobalSection DeserializeProjectConfigurationPlatformsGlobalSection(TextReader reader, ref string currentLine, PreOrPostSolution preOrPostSolution)
        {
            var projectConfigurationPlatformsGlobalSection = new ProjectConfigurationPlatformsGlobalSection
            {
                Name = ProjectConfigurationPlatformsGlobalSection.SolutionFileGlobalSectionName,
                PreOrPostSolution = preOrPostSolution
            };

            currentLine = reader.ReadLine().Trim();

            while (!SolutionFileTextSerializer.GlobalSectionEndRegex.IsMatch(currentLine))
            {
                var assignmentTokens = currentLine.Split("=");

                var targetToken = assignmentTokens[0].Trim();
                var valueToken  = assignmentTokens[1].Trim();

                var projectBuildConfigurationTokens = targetToken.Split(new string[] { Constants.SolutionProjectConfigurationTokenSeparator }, 3, StringSplitOptions.None);

                var projectGuidToken = projectBuildConfigurationTokens[0];
                var solutionBuildConfigurationToken = projectBuildConfigurationTokens[1];
                var indicatorToken = projectBuildConfigurationTokens[2];

                var projectGUID = Guid.Parse(projectGuidToken);
                var solutionBuildConfiguration = SolutionFileTextSerializer.DeserializeSolutionBuildConfiguration(solutionBuildConfigurationToken);
                var indicator = SolutionUtilities.ToProjectConfigurationIndicator(indicatorToken);
                var mappedSolutionBuildConfiguration = SolutionFileTextSerializer.DeserializeSolutionBuildConfiguration(valueToken);

                var projectBuildConfigurationMapping = new ProjectBuildConfigurationMapping
                {
                    ProjectGUID = projectGUID,
                    SolutionBuildConfiguration       = solutionBuildConfiguration,
                    ProjectConfigurationIndicator    = indicator,
                    MappedSolutionBuildConfiguration = mappedSolutionBuildConfiguration,
                };

                projectConfigurationPlatformsGlobalSection.ProjectBuildConfigurationMappings.Add(projectBuildConfigurationMapping);

                currentLine = reader.ReadLine().Trim();
            }

            return(projectConfigurationPlatformsGlobalSection);
        }
コード例 #7
0
        public void Serialize(TextWriter writer, SolutionFile solutionFile)
        {
            writer.WriteLine(); // Blank first line.

            var formatVersionLine = $"Microsoft Visual Studio Solution File, Format Version {solutionFile.FormatVersion.Major}.{solutionFile.FormatVersion.Minor:00}";

            writer.WriteLine(formatVersionLine);
            writer.WriteLine(solutionFile.VisualStudioMoniker);
            var vsVersionLine = $"VisualStudioVersion = {solutionFile.VisualStudioVersion}";

            writer.WriteLine(vsVersionLine);
            var vsMinimumVersionLine = $"MinimumVisualStudioVersion = {solutionFile.MinimumVisualStudioVersion}";

            writer.WriteLine(vsMinimumVersionLine);

            SolutionFileTextSerializer.SerializeProjectReferences(writer, solutionFile);

            SolutionFileTextSerializer.SerializeGlobals(writer, solutionFile);

            // Blank last line for free due to prior WriteLine().
        }
コード例 #8
0
        private static void DeserializeGlobal(TextReader reader, ref string currentLine, SolutionFile solutionFile)
        {
            if (!SolutionFileTextSerializer.GlobalSectionRegex.IsMatch(currentLine))
            {
                throw new Exception($"Unknown line.\nExpected: \"GlobalSection\".\nFound: {currentLine}");
            }

            var globalSectionMatches = Regex.Matches(currentLine, SolutionFileTextSerializer.GlobalSectionLineValuesRegexPattern);

            var sectionName          = globalSectionMatches[0].Value.TrimStart('(').TrimEnd(')');
            var preOrPostSolutionStr = globalSectionMatches[1].Value;

            var preOrPostSolution = SolutionUtilities.ToPreOrPostSolution(preOrPostSolutionStr);

            ISolutionFileGlobalSection globalSection;

            switch (sectionName)
            {
            case SolutionConfigurationPlatformsGlobalSection.SolutionFileGlobalSectionName:
                globalSection = SolutionFileTextSerializer.DeserializeSolutionConfigurationPlatformsGlobalSection(reader, ref currentLine, preOrPostSolution);
                break;

            case ProjectConfigurationPlatformsGlobalSection.SolutionFileGlobalSectionName:
                globalSection = SolutionFileTextSerializer.DeserializeProjectConfigurationPlatformsGlobalSection(reader, ref currentLine, preOrPostSolution);
                break;

            case NestedProjectsSolutionFileGlobalSection.SolutionFileGlobalSectionName:
                globalSection = SolutionFileTextSerializer.DeserializeNestedProjectsGlobalSection(reader, ref currentLine, preOrPostSolution);
                break;

            default:
                globalSection = SolutionFileTextSerializer.DeserializeGeneralGlobal(reader, ref currentLine, sectionName, preOrPostSolution);
                break;
            }
            solutionFile.GlobalSections.Add(globalSection);
        }
コード例 #9
0
        private static void SerializeGlobals(TextWriter writer, SolutionFile solutionFile)
        {
            var tabinatedWriter = new TabinatedWriter(writer);

            tabinatedWriter.WriteLine("Global");

            tabinatedWriter.IncreaseTabination();

            var globalSections        = new List <ISolutionFileGlobalSection>(solutionFile.GlobalSections);
            var globalSectionsInOrder = new List <ISolutionFileGlobalSection>();

            // SolutionConfigurationPlatforms.
            var solutionConfigurationPlatforms = globalSections.GetSolutionConfigurationPlatformsGlobalSection(); // Must have.

            globalSectionsInOrder.Add(solutionConfigurationPlatforms);
            globalSections.Remove(solutionConfigurationPlatforms);

            // ProjectConfigurationPlatforms.
            var hasProjectConfigurationPlatforms = globalSections.HasProjectConfigurationPlatformsGlobalSection(out var projectConfigurationPlatforms); // Can have.

            if (hasProjectConfigurationPlatforms)
            {
                globalSectionsInOrder.Add(projectConfigurationPlatforms);
                globalSections.Remove(projectConfigurationPlatforms);
            }

            // Solution properties.
            var solutionProperties = globalSections.GetGlobalSectionByName <GeneralSolutionFileGlobalSection>(Constants.SolutionPropertiesSolutionGlobalSectionName); // Must have.

            globalSectionsInOrder.Add(solutionProperties);
            globalSections.Remove(solutionProperties);

            // Nested projects.
            var hasNestedProjects = globalSections.HasNestedProjectsGlobalSection(out var nestedProjects); // Can have.

            if (hasNestedProjects)
            {
                globalSectionsInOrder.Add(nestedProjects);
                globalSections.Remove(nestedProjects);
            }

            // Extensibility globals.
            var hasExtensibilityGlobals = globalSections.HasGlobalSectionByName <GeneralSolutionFileGlobalSection>(Constants.ExtensibilityGlobalsSolutionGlobalSectionName, out var extensibilityGlobals); // Can have.

            if (hasExtensibilityGlobals)
            {
                globalSectionsInOrder.Add(extensibilityGlobals);
                globalSections.Remove(extensibilityGlobals);
            }

            // All others that remain.
            globalSectionsInOrder.AddRange(globalSections);

            foreach (var globalSection in globalSectionsInOrder)
            {
                if (globalSection is ISerializableSolutionFileGlobalSection serializableGlobalSection)
                {
                    SolutionFileTextSerializer.SerializeGlobal(tabinatedWriter, serializableGlobalSection);
                }
                else
                {
                    throw new IOException($"Unable to serialize solution file global section type: {globalSection.GetType().FullName}");
                }
            }
            tabinatedWriter.DecreaseTabination();

            tabinatedWriter.WriteLine("EndGlobal");
        }