void WriteProjects (SolutionFolder folder, string baseDirectory, StreamWriter writer, bool saveProjects, IProgressMonitor monitor) { monitor.BeginStepTask (GettextCatalog.GetString ("Saving projects"), folder.Items.Count, 1); foreach (SolutionItem ce in folder.Items.ToArray ()) { string[] l = null; if (ce is SolutionEntityItem) { SolutionEntityItem item = (SolutionEntityItem) ce; MSBuildHandler handler = MSBuildProjectService.GetItemHandler (item); if (saveProjects) { try { handler.SavingSolution = true; item.Save (monitor); } finally { handler.SavingSolution = false; } } l = handler.SlnProjectContent; writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""", handler.TypeGuid, item.Name, FileService.NormalizeRelativePath (FileService.AbsoluteToRelativePath ( baseDirectory, item.FileName)).Replace ('/', '\\'), ce.ItemId); DataItem data = handler.WriteSlnData (); if (data != null && data.HasItemData) { writer.WriteLine ("\tProjectSection(MonoDevelopProperties) = preProject"); WriteDataItem (writer, data); writer.WriteLine ("\tEndProjectSection"); } if (item.ItemDependencies.Count > 0 || handler.UnresolvedProjectDependencies != null) { writer.WriteLine ("\tProjectSection(ProjectDependencies) = postProject"); foreach (var dep in item.ItemDependencies) writer.WriteLine ("\t\t{0} = {0}", dep.ItemId); if (handler.UnresolvedProjectDependencies != null) { foreach (var dep in handler.UnresolvedProjectDependencies) writer.WriteLine ("\t\t{0} = {0}", dep); } writer.WriteLine ("\tEndProjectSection"); } } else if (ce is SolutionFolder) { //Solution SlnData slnData = GetSlnData (ce); if (slnData == null) { // Solution folder slnData = new SlnData (); ce.ExtendedProperties [typeof (SlnFileFormat)] = slnData; } l = slnData.Extra; writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""", MSBuildProjectService.FolderTypeGuid, ce.Name, ce.Name, ce.ItemId); // Folder files WriteFolderFiles (writer, (SolutionFolder) ce); //Write custom properties MSBuildSerializer ser = new MSBuildSerializer (folder.ParentSolution.FileName); DataItem data = (DataItem) ser.Serialize (ce, typeof(SolutionFolder)); if (data.HasItemData) { writer.WriteLine ("\tProjectSection(MonoDevelopProperties) = preProject"); WriteDataItem (writer, data); writer.WriteLine ("\tEndProjectSection"); } } if (l != null) { foreach (string s in l) writer.WriteLine (s); } writer.WriteLine ("EndProject"); if (ce is SolutionFolder) WriteProjects (ce as SolutionFolder, baseDirectory, writer, saveProjects, monitor); monitor.Step (1); } monitor.EndTask (); }
void WriteFileInternal (string file, Solution solution, string baseDir, MSBuildFileFormat format, bool saveProjects, IProgressMonitor monitor) { SolutionFolder c = solution.RootFolder; using (StreamWriter sw = new StreamWriter (file, false, Encoding.UTF8)) { sw.NewLine = "\r\n"; SlnData slnData = GetSlnData (c); if (slnData == null) { // If a non-msbuild project is being converted by just // changing the fileformat, then create the SlnData for it slnData = new SlnData (); c.ExtendedProperties [typeof (SlnFileFormat)] = slnData; } slnData.UpdateVersion (format); sw.WriteLine (); //Write Header sw.WriteLine ("Microsoft Visual Studio Solution File, Format Version " + slnData.VersionString); sw.WriteLine (slnData.HeaderComment); if (slnData.VisualStudioVersion != null) sw.WriteLine ("VisualStudioVersion = {0}", slnData.VisualStudioVersion); if (slnData.MinimumVisualStudioVersion != null) sw.WriteLine ("MinimumVisualStudioVersion = {0}", slnData.MinimumVisualStudioVersion); //Write the projects monitor.BeginTask (GettextCatalog.GetString ("Saving projects"), 1); WriteProjects (c, baseDir, sw, saveProjects, monitor); monitor.EndTask (); //Write the lines for unknownProjects foreach (string l in slnData.UnknownProjects) sw.WriteLine (l); //Write the Globals sw.WriteLine ("Global"); //Write SolutionConfigurationPlatforms //FIXME: SolutionConfigurations? sw.WriteLine ("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"); foreach (SolutionConfiguration config in solution.Configurations) sw.WriteLine ("\t\t{0} = {0}", ToSlnConfigurationId (config)); sw.WriteLine ("\tEndGlobalSection"); //Write ProjectConfigurationPlatforms sw.WriteLine ("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution"); List<string> list = new List<string> (); WriteProjectConfigurations (solution, list); list.Sort (StringComparer.Create (CultureInfo.InvariantCulture, true)); foreach (string s in list) sw.WriteLine (s); //Write lines for projects we couldn't load if (slnData.SectionExtras.ContainsKey ("ProjectConfigurationPlatforms")) { foreach (string s in slnData.SectionExtras ["ProjectConfigurationPlatforms"]) sw.WriteLine ("\t\t{0}", s); } sw.WriteLine ("\tEndGlobalSection"); //Write Nested Projects ICollection<SolutionFolder> folders = solution.RootFolder.GetAllItems<SolutionFolder> (); if (folders.Count > 1) { // If folders ==1, that's the root folder sw.WriteLine ("\tGlobalSection(NestedProjects) = preSolution"); foreach (SolutionFolder folder in folders) { if (folder.IsRoot) continue; WriteNestedProjects (folder, solution.RootFolder, sw); } sw.WriteLine ("\tEndGlobalSection"); } //Write custom properties MSBuildSerializer ser = new MSBuildSerializer (solution.FileName); DataItem data = (DataItem) ser.Serialize (solution, typeof(Solution)); if (data.HasItemData) { sw.WriteLine ("\tGlobalSection(MonoDevelopProperties) = preSolution"); WriteDataItem (sw, data); sw.WriteLine ("\tEndGlobalSection"); } // Write custom properties for configurations foreach (SolutionConfiguration conf in solution.Configurations) { data = (DataItem) ser.Serialize (conf); if (data.HasItemData) { sw.WriteLine ("\tGlobalSection(MonoDevelopProperties." + conf.Id + ") = preSolution"); WriteDataItem (sw, data); sw.WriteLine ("\tEndGlobalSection"); } } //Write 'others' if (slnData.GlobalExtra != null) { foreach (string s in slnData.GlobalExtra) sw.WriteLine (s); } sw.WriteLine ("EndGlobal"); } }