void RemoveItemFromSolution(SolutionSectionItem item) { SD.SolutionSection section = GetExtensibilityGlobalsSection(); section.Remove(item.Name); nonPersistedSolutionItems.Add(item); solution.Save(); }
public SolutionSection ReadSection(bool isGlobal) { if (currentLine == null) { return(null); } Match match = sectionHeaderPattern.Match(currentLine); if (!match.Success) { return(null); } NextLine(); SolutionSection section = new SolutionSection(match.Groups["Name"].Value, match.Groups["Type"].Value); ReadSectionEntries(section); string expectedLine = isGlobal ? "EndGlobalSection" : "EndProjectSection"; if ((currentLine ?? string.Empty).Trim() != expectedLine) { throw Error("Expected " + expectedLine); } NextLine(); return(section); }
SolutionSection GenerateProjectConfigurationSection(ISolution solution) { SolutionSection section = new SolutionSection("ProjectConfigurationPlatforms", "postSolution"); foreach (var project in solution.AllItems.OfType <IProject>()) { foreach (var configuration in solution.ConfigurationNames) { foreach (var platform in solution.PlatformNames) { var solutionConfig = new ConfigurationAndPlatform(configuration, platform); var projectConfig = project.ConfigurationMapping.GetProjectConfiguration(solutionConfig); string key = GuidToString(project.IdGuid) + "." + solutionConfig; string value = projectConfig.Configuration + "|" + MSBuildInternals.FixPlatformNameForSolution(projectConfig.Platform); section.Add(key + ".ActiveCfg", value); if (project.ConfigurationMapping.IsBuildEnabled(solutionConfig)) { section.Add(key + ".Build.0", value); } if (project.ConfigurationMapping.IsDeployEnabled(solutionConfig)) { section.Add(key + ".Deploy.0", value); } } } } return(section); }
public void WriteSolutionItem(ISolutionItem item) { ISolutionFolder folder = item as ISolutionFolder; IProject project = item as IProject; if (folder != null) { WriteProjectHeader(ProjectTypeGuids.SolutionFolder, folder.Name, folder.Name, folder.IdGuid); // File items are represented as nodes in the tree, but they're actually // saved as properties on their containing folder. SolutionSection section = new SolutionSection("SolutionItems", "preProject"); foreach (var file in folder.Items.OfType <ISolutionFileItem>()) { string location = FileUtility.GetRelativePath(basePath, file.FileName); section.Add(location, location); } WriteProjectSection(section); writer.WriteLine("EndProject"); } else if (project != null) { string location = FileUtility.GetRelativePath(basePath, project.FileName); WriteProjectHeader(project.TypeGuid, project.Name, location, project.IdGuid); foreach (var section in project.ProjectSections) { WriteProjectSection(section); } writer.WriteLine("EndProject"); } }
SolutionSectionItem GetItemFromSolution(string name) { SD.SolutionSection section = GetExtensibilityGlobalsSection(); if (section != null) { return(GetMatchingSolutionItem(section, name)); } return(null); }
public void WriteGlobalSection(SolutionSection section) { if (section.Count != 0) { writer.WriteLine("\tGlobalSection({0}) = {1}", section.SectionName, section.SectionType); WriteSectionEntries(section); writer.WriteLine("\tEndGlobalSection"); } }
public void VariableValue_SetNewValueForVariableWhenExtensibilityGlobalsDoesNotExist_ExtensibilityGlobalsSectionCreated() { CreateSolution(); globals.set_VariableValue("test", "new-value"); SD.SolutionSection section = GetExtensibilityGlobalsSection(); Assert.IsNull(section); }
public void VariablePersists_SetToTrueAfterNewVariableAdded_ExtensibilityGlobalsSectionAddedWithPostSolutionType() { CreateSolution(); globals.set_VariableValue("test", "new-value"); globals.set_VariablePersists("test", true); SD.SolutionSection section = GetExtensibilityGlobalsSection(); Assert.AreEqual("postSolution", section.SectionType); }
SolutionSectionItem GetMatchingSolutionItem(SD.SolutionSection section, string name) { string matchedName = section.Keys.SingleOrDefault(key => IsMatchIgnoringCase(key, name)); if (matchedName != null) { return(new SolutionSectionItem(section, matchedName)); } return(null); }
public void WriteSectionEntries(SolutionSection section) { foreach (var entry in section) { writer.Write("\t\t"); writer.Write(entry.Key); writer.Write(" = "); writer.Write(entry.Value); writer.WriteLine(); } }
SD.SolutionSection GetOrCreateExtensibilityGlobalsSection() { SD.SolutionSection section = GetExtensibilityGlobalsSection(); if (section != null) { return(section); } var newSection = new SD.SolutionSection(ExtensibilityGlobalsSectionName, "postSolution"); solution.Sections.Add(newSection); return(newSection); }
void LoadProjectConfigurations(SolutionSection section, Dictionary <Guid, ProjectLoadInformation> projectInfoDict) { foreach (var pair in section) { // pair is an entry like this: '{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU' if (pair.Key.EndsWith(".ActiveCfg", StringComparison.OrdinalIgnoreCase)) { Guid guid; ConfigurationAndPlatform solutionConfig; if (!TryParseProjectConfigurationKey(pair.Key, out guid, out solutionConfig)) { continue; } ProjectLoadInformation projectInfo; if (!projectInfoDict.TryGetValue(guid, out projectInfo)) { continue; } var projectConfig = ConfigurationAndPlatform.FromKey(pair.Value); if (projectConfig == default(ConfigurationAndPlatform)) { continue; } projectInfo.ConfigurationMapping.SetProjectConfiguration(solutionConfig, projectConfig); // Disable build if we see a '.ActiveCfg' entry. projectInfo.ConfigurationMapping.SetBuildEnabled(solutionConfig, false); } } // Enable build/deploy if we see the corresponding entries: foreach (var pair in section) { // pair is an entry like this: '{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Debug|Any CPU.Build.0 = Debug|Any CPU' Guid guid; ConfigurationAndPlatform solutionConfig; if (!TryParseProjectConfigurationKey(pair.Key, out guid, out solutionConfig)) { continue; } ProjectLoadInformation projectInfo; if (!projectInfoDict.TryGetValue(guid, out projectInfo)) { continue; } if (pair.Key.EndsWith(".Build.0", StringComparison.OrdinalIgnoreCase)) { projectInfo.ConfigurationMapping.SetBuildEnabled(solutionConfig, true); } else if (pair.Key.EndsWith(".Deploy.0", StringComparison.OrdinalIgnoreCase)) { projectInfo.ConfigurationMapping.SetDeployEnabled(solutionConfig, true); } } }
public void VariablePersists_SetPersistToTrueTwice_VariableAddedToSolutionOnce() { CreateSolution(); globals.set_VariableValue("test", "one"); globals.set_VariablePersists("test", true); globals.set_VariablePersists("test", true); SD.SolutionSection section = GetExtensibilityGlobalsSection(); int count = section.Keys.Count(); Assert.AreEqual(1, count); }
SolutionSection GenerateSolutionConfigurationSection(IConfigurable solution) { SolutionSection section = new SolutionSection("SolutionConfigurationPlatforms", "preSolution"); foreach (var config in solution.ConfigurationNames) { foreach (var platform in solution.PlatformNames) { string key = config + "|" + platform; section.Add(key, key); } } return(section); }
internal void AddItemToSolution(string name) { if (ItemExistsInSolution(name)) { return; } SolutionSectionItem item = GetNonPersistedSolutionItem(name); nonPersistedSolutionItems.Remove(item); SD.SolutionSection section = GetOrCreateExtensibilityGlobalsSection(); section.Add(item.Name, item.Value); solution.Save(); }
public void GlobalSection() { SolutionSection section = new SolutionSection("ProjectConfigurationPlatforms", "postSolution"); section.Add("{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.ActiveCfg", "Debug|Any CPU"); section.Add("{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.ActiveCfg", "Release|Any CPU"); StringWriter w = new StringWriter(); new SolutionWriter(w).WriteGlobalSection(section); Assert.AreEqual("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" + w.NewLine + "\t\t{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" + w.NewLine + "\t\t{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.ActiveCfg = Release|Any CPU" + w.NewLine + "\tEndGlobalSection" + w.NewLine , w.ToString()); }
void ReadSectionEntries(SolutionSection section) { while (currentLine != null) { int pos = currentLine.IndexOf('='); if (pos < 0) { break; // end of section } string key = currentLine.Substring(0, pos).Trim(); string value = currentLine.Substring(pos + 1).Trim(); section.Add(key, value); NextLine(); } }
SolutionSection GenerateNestingSection(ISolution solution) { SolutionSection section = new SolutionSection("NestedProjects", "preSolution"); foreach (var item in solution.AllItems) { if (item is ISolutionFileItem) { continue; // file items are a special case as they're saved in their own section } if (item.ParentFolder != solution) { section.Add(GuidToString(item.IdGuid), GuidToString(item.ParentFolder.IdGuid)); } } return(section); }
public void DescriptionInSolutionConfigurationPlatforms() { // http://community.sharpdevelop.net/forums/t/19948.aspx string input = "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" + Environment.NewLine + "\t\tDebug|Any CPU = Debug|Any CPU" + Environment.NewLine + "\t\tRelease|Any CPU = Release|Any CPU" + Environment.NewLine + "\t\tDescription = Some fancy description of the application." + Environment.NewLine + "\tEndGlobalSection" + Environment.NewLine; var loader = new SolutionLoader(new StringReader(input)); SolutionSection section = loader.ReadSection(isGlobal: true); var configs = loader.LoadSolutionConfigurations(section).ToArray(); Assert.AreEqual(new[] { new ConfigurationAndPlatform("Debug", "Any CPU"), new ConfigurationAndPlatform("Release", "Any CPU") }, configs); }
/// <summary> /// Converts the 'NestedProjects' section into a dictionary from project GUID to parent solution folder. /// </summary> Dictionary <Guid, SolutionFolder> LoadNesting(SolutionSection section, IReadOnlyDictionary <Guid, SolutionFolder> solutionFolderDict) { var result = new Dictionary <Guid, SolutionFolder>(); foreach (var entry in section) { Guid idGuid; Guid parentGuid; if (Guid.TryParse(entry.Key, out idGuid) && Guid.TryParse(entry.Value, out parentGuid)) { SolutionFolder parentFolder; if (solutionFolderDict.TryGetValue(parentGuid, out parentFolder)) { result[idGuid] = parentFolder; } } } return(result); }
public void AddExtensibilityGlobalsSection() { var section = new SD.SolutionSection("ExtensibilityGlobals", "postSolution"); MSBuildSolution.GlobalSections.Add(section); }
SD.SolutionSection GetOrCreateExtensibilityGlobalsSection() { SD.SolutionSection section = GetExtensibilityGlobalsSection(); if (section != null) { return section; } var newSection = new SD.SolutionSection(ExtensibilityGlobalsSectionName, "postSolution"); solution.Sections.Add(newSection); return newSection; }