Serialize() { var document = new System.Xml.XmlDocument(); var projectEl = this.CreateRootProject(document); projectEl.SetAttribute("ToolsVersion", "4.0"); // TODO: get this number from VisualC var filtersEl = document.CreateVSItemGroup(parentEl: projectEl); foreach (var filter in this.Filters) { var filterEl = document.CreateVSElement("Filter", parentEl: filtersEl); filterEl.SetAttribute("Include", filter.Key); document.CreateVSElement("UniqueIdentifier", new DeterministicGuid("VSFilter" + filter.Key).Guid.ToString("B").ToUpper(), parentEl: filterEl); var filesEl = document.CreateVSItemGroup(parentEl: projectEl); var extensions = new Bam.Core.StringArray(); foreach (var setting in filter.Value) { var path = setting.Include; var extension = System.IO.Path.GetExtension(path.Parse()).TrimStart(new[] { '.' }); extensions.AddUnique(extension); setting.Serialize(document, filesEl); } if (extensions.Count > 0) { document.CreateVSElement("Extensions", extensions.ToString(';'), parentEl: filterEl); } } return(document); }
Serialize() { var document = new System.Xml.XmlDocument(); var projectEl = this.CreateRootProject(document); projectEl.SetAttribute("ToolsVersion", "4.0"); // TODO: get this number from VisualC var filtersEl = document.CreateVSItemGroup(parentEl: projectEl); foreach (var filter in this.Filters) { var filterEl = document.CreateVSElement("Filter", parentEl: filtersEl); filterEl.SetAttribute("Include", filter.Key); document.CreateVSElement("UniqueIdentifier", new DeterministicGuid("VSFilter" + filter.Key).Guid.ToString("B").ToUpper(), parentEl: filterEl); var filesEl = document.CreateVSItemGroup(parentEl: projectEl); var extensions = new Bam.Core.StringArray(); foreach (var setting in filter.Value) { var path = setting.Include; var extension = System.IO.Path.GetExtension(path.Parse()).TrimStart(new[] { '.' }); extensions.AddUnique(extension); setting.Serialize(document, filesEl); } if (extensions.Count > 0) { document.CreateVSElement("Extensions", extensions.ToString(';'), parentEl: filterEl); } } return document; }
SerializeProperties( System.Xml.XmlDocument document, System.Xml.XmlElement parentEl) { if (this.Type == EType.NA) { Bam.Core.Log.DebugMessage("Defaulting project {0} to type Utility", this.Project.ProjectPath); this.Type = EType.Utility; this.EnableIntermediatePath(); } else { if (System.String.IsNullOrEmpty(this.PlatformToolset)) { throw new Bam.Core.Exception("Platform toolset not set for project {0}", this.Project.ProjectPath); } } var propGroup = document.CreateVSPropertyGroup(label: "Configuration", condition: this.ConditionText, parentEl: parentEl); document.CreateVSElement("ConfigurationType", value: this.Type.ToString(), parentEl: propGroup); document.CreateVSElement("PlatformToolset", value: this.PlatformToolset.ToString(), parentEl: propGroup); document.CreateVSElement("UseDebugLibraries", value: this.UseDebugLibraries.ToString().ToLower(), parentEl: propGroup); document.CreateVSElement("CharacterSet", value: this.CharacterSet.ToString(), parentEl: propGroup); document.CreateVSElement("WholeProgramOptimization", value: this.WholeProgramOptimization.ToString().ToLower(), parentEl: propGroup); }
Serialize( System.Xml.XmlDocument document, System.Xml.XmlElement parentEl) { if ((this.Settings.Count == 0) && (this.Include == null)) { return; } var group = document.CreateVSElement(this.GetGroupName(), parentEl: parentEl); if (null != this.Include) { var path = this.Include.ToString(); var relPath = Bam.Core.RelativePathUtilities.GetPath(path, this.Project.ProjectPath); if (Bam.Core.RelativePathUtilities.IsPathAbsolute(relPath)) { group.SetAttribute("Include", relPath); } else { group.SetAttribute("Include", System.String.Format("$(ProjectDir){0}", relPath)); } } foreach (var setting in this.Settings.OrderBy(pair => pair.Name)) { document.CreateVSElement(setting.Name, value: setting.Value, condition: setting.Condition, parentEl: group); } }
CreateVSItemDefinitionGroup( this System.Xml.XmlDocument document, string condition = null, System.Xml.XmlElement parentEl = null) { return(document.CreateVSElement("ItemDefinitionGroup", condition: condition, parentEl: parentEl)); }
CreateRootProject( System.Xml.XmlDocument document) { var project = document.CreateVSElement("Project"); document.AppendChild(project); return(project); }
CreateVSImportGroup( this System.Xml.XmlDocument document, string label, System.Xml.XmlElement parentEl = null) { var import = document.CreateVSElement("ImportGroup", parentEl: parentEl); import.SetAttribute("Label", label); return(import); }
CreateVSImport( this System.Xml.XmlDocument document, string importPath, System.Xml.XmlElement parentEl = null) { var import = document.CreateVSElement("Import", parentEl: parentEl); import.SetAttribute("Project", importPath); return(import); }
Serialize( System.Xml.XmlDocument document, System.Xml.XmlElement parentEl) { if ((this.Settings.Count == 0) && (this.Include == null)) { return; } var group = document.CreateVSElement(this.GetGroupName(), parentEl: parentEl); if (null != this.Include) { group.SetAttribute("Include", this.Include.Parse()); } foreach (var setting in this.Settings.OrderBy(pair => pair.Name)) { document.CreateVSElement(setting.Name, value: setting.Value, condition: setting.Condition, parentEl: group); } }
SerializeDependentProjects( System.Xml.XmlDocument document, System.Xml.XmlElement parentEl) { if (this.OrderOnlyDependentProjects.Count > 0) { var itemGroupEl = document.CreateVSItemGroup(parentEl: parentEl); foreach (var project in this.OrderOnlyDependentProjects) { var projectRefEl = document.CreateVSElement("ProjectReference", parentEl: itemGroupEl); projectRefEl.SetAttribute("Include", Bam.Core.RelativePathUtilities.GetPath(project.ProjectPath, this.ProjectPath)); document.CreateVSElement("Project", value: project.Guid.ToString("B"), parentEl: projectRefEl); document.CreateVSElement("LinkLibraryDependencies", value: "false", parentEl: projectRefEl); } } if (this.LinkDependentProjects.Count > 0) { var itemGroupEl = document.CreateVSItemGroup(parentEl: parentEl); foreach (var project in this.LinkDependentProjects) { var projectRefEl = document.CreateVSElement("ProjectReference", parentEl: itemGroupEl); projectRefEl.SetAttribute("Include", Bam.Core.RelativePathUtilities.GetPath(project.ProjectPath, this.ProjectPath)); document.CreateVSElement("Project", value: project.Guid.ToString("B"), parentEl: projectRefEl); document.CreateVSElement("LinkLibraryDependencies", value: "true", parentEl: projectRefEl); } } }
CreateVSItemGroup( this System.Xml.XmlDocument document, string label = null, System.Xml.XmlElement parentEl = null) { var itemGroup = document.CreateVSElement("ItemGroup", parentEl: parentEl); if (null != label) { itemGroup.SetAttribute("Label", label); } return(itemGroup); }
SerializeUserSettings() { var document = new System.Xml.XmlDocument(); var projectEl = this.CreateRootProject(document); var visualCMeta = Bam.Core.Graph.Instance.PackageMetaData <VisualC.MetaData>("VisualC"); projectEl.SetAttribute("ToolsVersion", visualCMeta.VCXProjToolsVersion); // the working directory appears to need to be the same in all configurations var el = document.CreateVSPropertyGroup(parentEl: projectEl); var debuggerFlavour = document.CreateVSElement("DebuggerFlavor"); debuggerFlavour.InnerText = "WindowsLocalDebugger"; var workingDir = document.CreateVSElement("LocalDebuggerWorkingDirectory"); workingDir.InnerText = (this.Module as C.ConsoleApplication).WorkingDirectory.Parse(); el.AppendChild(debuggerFlavour); el.AppendChild(workingDir); return(document); }
CreateVSPropertyGroup( this System.Xml.XmlDocument document, string label = null, string condition = null, System.Xml.XmlElement parentEl = null) { var propertyGroup = document.CreateVSElement("PropertyGroup", condition: condition, parentEl: parentEl); if (null != label) { propertyGroup.SetAttribute("Label", label); } return(propertyGroup); }
SerializePaths( System.Xml.XmlDocument document, System.Xml.XmlElement parentEl) { var propGroup = document.CreateVSPropertyGroup(condition: this.ConditionText, parentEl: parentEl); if (null != this.OutputDirectory) { document.CreateVSElement("OutDir", value: this.OutputDirectory, parentEl: propGroup); } if (null != this.IntermediateDirectory) { document.CreateVSElement("IntDir", value: this.IntermediateDirectory, parentEl: propGroup); } if (null != this.TargetName) { document.CreateVSElement("TargetName", value: this.TargetName, parentEl: propGroup); } if (null != this.TargetExt) { document.CreateVSElement("TargetExt", value: this.TargetExt, parentEl: propGroup); } }
Serialize() { var document = new System.Xml.XmlDocument(); var projectEl = this.CreateRootProject(document); projectEl.SetAttribute("DefaultTargets", "Build"); projectEl.SetAttribute("ToolsVersion", "12.0"); // TODO: get from VisualC package // define configurations in the project var configurationItemGroup = document.CreateVSItemGroup("ProjectConfigurations", projectEl); foreach (var config in this.Configurations) { var projectConfigEl = document.CreateVSElement("ProjectConfiguration", parentEl: configurationItemGroup); projectConfigEl.SetAttribute("Include", config.Value.FullName); document.CreateVSElement("Configuration", value: config.Value.ConfigurationName, parentEl: projectConfigEl); document.CreateVSElement("Platform", value: config.Value.PlatformName, parentEl: projectConfigEl); } // global properties var globalPropertyGroup = document.CreateVSPropertyGroup(label: "Globals", parentEl: projectEl); document.CreateVSElement("ProjectGuid", value: this.Guid.ToString("B").ToUpper(), parentEl: globalPropertyGroup); document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.Default.props", parentEl: projectEl); // configuration properties foreach (var config in this.Configurations) { config.Value.SerializeProperties(document, projectEl); } document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.props", parentEl: projectEl); // configuration paths foreach (var config in this.Configurations) { config.Value.SerializePaths(document, projectEl); } // tool settings foreach (var config in this.Configurations) { config.Value.SerializeSettings(document, projectEl); } // input files (these are VSSettingsGroups, but configuration agnostic) if (this.Sources.Count > 0) { var sourcesGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Sources) { foreach (var config in this.Configurations) { if (!config.Value.ContainsSource(group)) { group.AddSetting("ExcludedFromBuild", "true", config.Value.ConditionText); } } group.Serialize(document, sourcesGroup); } } if (this.Headers.Count > 0) { var headersGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Headers) { group.Serialize(document, headersGroup); } } if (this.Others.Count > 0) { var otherGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Others) { group.Serialize(document, otherGroup); } } if (this.Resources.Count > 0) { var resourceGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Resources) { group.Serialize(document, resourceGroup); } } // dependent projects this.SerializeDependentProjects(document, projectEl); document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.targets", parentEl: projectEl); return(document); }
Serialize() { var document = new System.Xml.XmlDocument(); var projectEl = this.CreateRootProject(document); projectEl.SetAttribute("DefaultTargets", "Build"); projectEl.SetAttribute("ToolsVersion", "12.0"); // TODO: get from VisualC package // define configurations in the project var configurationItemGroup = document.CreateVSItemGroup("ProjectConfigurations", projectEl); foreach (var config in this.Configurations) { var projectConfigEl = document.CreateVSElement("ProjectConfiguration", parentEl: configurationItemGroup); projectConfigEl.SetAttribute("Include", config.Value.FullName); document.CreateVSElement("Configuration", value: config.Value.ConfigurationName, parentEl: projectConfigEl); document.CreateVSElement("Platform", value: config.Value.PlatformName, parentEl: projectConfigEl); } // global properties var globalPropertyGroup = document.CreateVSPropertyGroup(label: "Globals", parentEl: projectEl); document.CreateVSElement("ProjectGuid", value: this.Guid.ToString("B").ToUpper(), parentEl: globalPropertyGroup); document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.Default.props", parentEl: projectEl); // configuration properties foreach (var config in this.Configurations) { config.Value.SerializeProperties(document, projectEl); } document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.props", parentEl: projectEl); // configuration paths foreach (var config in this.Configurations) { config.Value.SerializePaths(document, projectEl); } // tool settings foreach (var config in this.Configurations) { config.Value.SerializeSettings(document, projectEl); } // input files (these are VSSettingsGroups, but configuration agnostic) if (this.Sources.Count > 0) { var sourcesGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Sources) { foreach (var config in this.Configurations) { if (!config.Value.ContainsSource(group)) { group.AddSetting("ExcludedFromBuild", "true", config.Value.ConditionText); } } group.Serialize(document, sourcesGroup); } } if (this.Headers.Count > 0) { var headersGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Headers) { group.Serialize(document, headersGroup); } } if (this.Others.Count > 0) { var otherGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Others) { group.Serialize(document, otherGroup); } } if (this.Resources.Count > 0) { var resourceGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Resources) { group.Serialize(document, resourceGroup); } } // dependent projects this.SerializeDependentProjects(document, projectEl); document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.targets", parentEl: projectEl); return document; }
Serialize() { var document = new System.Xml.XmlDocument(); var projectEl = this.CreateRootProject(document); projectEl.SetAttribute("DefaultTargets", "Build"); var visualCMeta = Bam.Core.Graph.Instance.PackageMetaData <VisualC.MetaData>("VisualC"); projectEl.SetAttribute("ToolsVersion", visualCMeta.VCXProjToolsVersion); // define configurations in the project var configurationItemGroup = document.CreateVSItemGroup("ProjectConfigurations", projectEl); foreach (var config in this.Configurations) { var projectConfigEl = document.CreateVSElement("ProjectConfiguration", parentEl: configurationItemGroup); projectConfigEl.SetAttribute("Include", config.Value.FullName); document.CreateVSElement("Configuration", value: config.Value.ConfigurationName, parentEl: projectConfigEl); document.CreateVSElement("Platform", value: config.Value.PlatformName, parentEl: projectConfigEl); } // global properties var globalPropertyGroup = document.CreateVSPropertyGroup(label: "Globals", parentEl: projectEl); document.CreateVSElement("ProjectGuid", value: this.Guid.ToString("B").ToUpper(), parentEl: globalPropertyGroup); var vcEnv = visualCMeta.Environment(GetModuleBitDepth(this.Module)); if (vcEnv.ContainsKey("WindowsSDKVersion")) { var windowssdk_version = vcEnv["WindowsSDKVersion"].First().ToString().TrimEnd(System.IO.Path.DirectorySeparatorChar); document.CreateVSElement("WindowsTargetPlatformVersion", value: windowssdk_version, parentEl: globalPropertyGroup); } else { // appears to automatically fall back to 8.1 } document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.Default.props", parentEl: projectEl); // configuration properties foreach (var config in this.Configurations) { config.Value.SerializeProperties(document, projectEl); } document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.props", parentEl: projectEl); if (this.AssemblyFiles.Any()) { var extensionSettings = document.CreateVSImportGroup("ExtensionSettings", parentEl: projectEl); document.CreateVSImport(@"$(VCTargetsPath)\BuildCustomizations\masm.props", parentEl: extensionSettings); } // configuration paths foreach (var config in this.Configurations) { config.Value.SerializePaths(document, projectEl); } // tool settings foreach (var config in this.Configurations) { config.Value.SerializeSettings(document, projectEl); } // input files (these are VSSettingsGroups, but configuration agnostic) if (this.Sources.Count > 0) { var sourcesGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Sources) { foreach (var config in this.Configurations) { if (!config.Value.ContainsSource(group)) { group.AddSetting("ExcludedFromBuild", "true", config.Value.ConditionText); } } group.Serialize(document, sourcesGroup); } } if (this.Headers.Count > 0) { var headersGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Headers) { foreach (var config in this.Configurations) { if (!config.Value.ContainsHeader(group)) { group.AddSetting("ExcludedFromBuild", "true", config.Value.ConditionText); } } group.Serialize(document, headersGroup); } } if (this.Others.Count > 0) { var otherGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Others) { group.Serialize(document, otherGroup); } } if (this.Resources.Count > 0) { var resourceGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.Resources) { foreach (var config in this.Configurations) { if (!config.Value.ContainsResourceFile(group)) { group.AddSetting("ExcludedFromBuild", "true", config.Value.ConditionText); } } group.Serialize(document, resourceGroup); } } if (this.AssemblyFiles.Count > 0) { var assemblerGroup = document.CreateVSItemGroup(parentEl: projectEl); foreach (var group in this.AssemblyFiles) { foreach (var config in this.Configurations) { if (!config.Value.ContainsAssemblyFile(group)) { group.AddSetting("ExcludedFromBuild", "true", config.Value.ConditionText); } } group.Serialize(document, assemblerGroup); } } // dependent projects this.SerializeDependentProjects(document, projectEl); document.CreateVSImport(@"$(VCTargetsPath)\Microsoft.Cpp.targets", parentEl: projectEl); if (this.AssemblyFiles.Any()) { var extensionTargets = document.CreateVSImportGroup("ExtensionTargets", parentEl: projectEl); document.CreateVSImport(@"$(VCTargetsPath)\BuildCustomizations\masm.targets", parentEl: extensionTargets); } return(document); }