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); }