/// <summary> /// Creates a project file that references each generated C# code file for data access. /// </summary> /// <param name="path">The path where the project file should be created.</param> /// <param name="projectName">The name of the project.</param> /// <param name="tableList">The list of tables code files were created for.</param> /// <param name="daoSuffix">The suffix to append to the name of each data access class.</param> internal static void CreateProjectFile(string path, string projectName, List <Table> tableList, string daoSuffix) { string projectXml = AppUtility.GetResource("PocoSqlGenerator.Resources.Project.xml"); var document = new XmlDocument(); document.LoadXml(projectXml); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable); namespaceManager.AddNamespace(String.Empty, "http://schemas.microsoft.com/developer/msbuild/2003"); namespaceManager.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003"); var selectSingleNode = document.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:ProjectGuid", namespaceManager); if (selectSingleNode != null) { selectSingleNode.InnerText = "{" + Guid.NewGuid().ToString() + "}"; } var singleNode = document.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:RootNamespace", namespaceManager); if (singleNode != null) { singleNode.InnerText = projectName; } var xmlNode = document.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:AssemblyName", namespaceManager); if (xmlNode != null) { xmlNode.InnerText = projectName; } XmlNode itemGroupNode = document.SelectSingleNode("/msbuild:Project/msbuild:ItemGroup[msbuild:Compile]", namespaceManager); foreach (Table table in tableList) { string className = AppUtility.FormatClassName(table.Name); XmlNode dtoCompileNode = document.CreateElement("Compile", "http://schemas.microsoft.com/developer/msbuild/2003"); XmlAttribute dtoAttribute = document.CreateAttribute("Include"); dtoAttribute.Value = className + ".cs"; if (dtoCompileNode.Attributes != null) { dtoCompileNode.Attributes.Append(dtoAttribute); } if (itemGroupNode != null) { itemGroupNode.AppendChild(dtoCompileNode); } } document.Save(Path.Combine(path, projectName + ".csproj")); }
/// <summary> /// Creates the AssemblyInfo.cs file for the project. /// </summary> /// <param name="path">The root path of the project.</param> /// <param name="assemblyTitle">The title of the assembly.</param> /// <param name="databaseName">The name of the database the assembly provides access to.</param> internal static void CreateAssemblyInfo(string path, string assemblyTitle, string databaseName) { string assemblyInfo = AppUtility.GetResource("PocoSqlGenerator.Resources.AssemblyInfo.txt"); assemblyInfo.Replace("#AssemblyTitle", assemblyTitle); assemblyInfo.Replace("#DatabaseName", databaseName); string propertiesDirectory = Path.Combine(path, "Properties"); if (Directory.Exists(propertiesDirectory) == false) { Directory.CreateDirectory(propertiesDirectory); } File.WriteAllText(Path.Combine(propertiesDirectory, "AssemblyInfo.cs"), assemblyInfo); }