void IProject.Serialize() { System.Xml.XmlDocument xmlDocument = null; try { var projectLocationUri = new System.Uri(this.PathName, System.UriKind.RelativeOrAbsolute); xmlDocument = new System.Xml.XmlDocument(); xmlDocument.AppendChild(xmlDocument.CreateComment("Automatically generated by BuildAMation v" + Bam.Core.State.VersionString)); // TODO: this needs to be from the Toolset var versionString = DotNetFramework.DotNet.VersionString; var project = new MSBuildProject(xmlDocument, versionString); var generalGroup = project.CreatePropertyGroup(); generalGroup.CreateProperty("ProjectGuid", this.ProjectGuid.ToString("B").ToUpper()); // default configuration and platform { var defaultConfiguration = generalGroup.CreateProperty("Configuration", "Debug"); defaultConfiguration.Condition = " '$(Configuration)' == '' "; } { var defaultPlatform = generalGroup.CreateProperty("Platform", "AnyCPU"); defaultPlatform.Condition = " '$(Platform)' == '' "; } generalGroup.CreateProperty("TargetFrameworkVersion", "v" + versionString); // configurations // TODO: convert to var foreach (ProjectConfiguration configuration in this.ProjectConfigurations) { configuration.SerializeCSBuild(project, projectLocationUri); } // source files if (this.SourceFileCollection.Count > 0) { this.SourceFileCollection.SerializeCSBuild(project, projectLocationUri, this.PackageUri); } // application definition and page files if ((this.ApplicationDefinitionFile != null) || (this.PageFiles.Count > 0)) { var applicationDefinitionGroup = project.CreateItemGroup(); // application definition if (this.ApplicationDefinitionFile != null) { var xamlRelativePath = Bam.Core.RelativePathUtilities.GetPath(this.ApplicationDefinitionFile.RelativePath, projectLocationUri); var applicationDefinition = applicationDefinitionGroup.CreateItem("ApplicationDefinition", xamlRelativePath); applicationDefinition.CreateMetaData("Generator", "MSBuild:Compile"); applicationDefinition.CreateMetaData("SubType", "Designer"); var sourcePathname = xamlRelativePath + ".cs"; var associatedSource = applicationDefinitionGroup.CreateItem("Compile", sourcePathname); associatedSource.CreateMetaData("DependentUpon", System.IO.Path.GetFileName(xamlRelativePath)); associatedSource.CreateMetaData("SubType", "Code"); } // page files // TODO: convert to var foreach (ProjectFile pageFile in this.PageFiles) { var xamlRelativePath = Bam.Core.RelativePathUtilities.GetPath(pageFile.RelativePath, projectLocationUri); var applicationDefinition = applicationDefinitionGroup.CreateItem("Page", xamlRelativePath); applicationDefinition.CreateMetaData("Generator", "MSBuild:Compile"); applicationDefinition.CreateMetaData("SubType", "Designer"); var sourcePathname = xamlRelativePath + ".cs"; var associatedSource = applicationDefinitionGroup.CreateItem("Compile", sourcePathname); associatedSource.CreateMetaData("DependentUpon", System.IO.Path.GetFileName(xamlRelativePath)); associatedSource.CreateMetaData("SubType", "Code"); } } // project dependencies if (this.DependentProjectList.Count > 0) { var dependencyItemGroup = project.CreateItemGroup(); foreach (var dependentProject in this.DependentProjectList) { var relativePath = Bam.Core.RelativePathUtilities.GetPath(dependentProject.PathName, this.PathName); var projectReference = dependencyItemGroup.CreateItem("ProjectReference", relativePath); projectReference.CreateMetaData("Project", dependentProject.Guid.ToString("B").ToUpper()); projectReference.CreateMetaData("Name", dependentProject.Name); } } // project references if (this.ReferencesList.Count > 0) { var referenceItemGroup = project.CreateItemGroup(); foreach (var reference in this.ReferencesList) { var noExtReference = reference; if (noExtReference.EndsWith(".dll")) { noExtReference = reference.Remove(noExtReference.Length - 4); } referenceItemGroup.CreateItem("Reference", noExtReference); } } // import C# project props project.CreateImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets"); } catch (Bam.Core.Exception exception) { var message = System.String.Format("Xml construction error from project '{0}'", this.PathName); throw new Bam.Core.Exception(message, exception); } // write XML to disk System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(this.PathName)); var xmlWriterSettings = new System.Xml.XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.CloseOutput = true; xmlWriterSettings.OmitXmlDeclaration = false; xmlWriterSettings.NewLineOnAttributes = false; try { using (var xmlWriter = System.Xml.XmlWriter.Create(this.PathName, xmlWriterSettings)) { xmlDocument.Save(xmlWriter); xmlWriter.WriteWhitespace(xmlWriterSettings.NewLineChars); } } catch (Bam.Core.Exception exception) { var message = System.String.Format("Serialization error from project '{0}'", this.PathName); throw new Bam.Core.Exception(message, exception); } }