Example #1
0
 public bool GenerateCSProject(string projectDirectory, string[] tables, string[] newTypes, ProjectVesion projectVesion, out string projectFileName)
 {
     projectFileName = string.Format("{0}.csproj", CodeNamespace);
     var model = new
     {
         ApplicationStartupPath = ApplicationStartupPath,
         ProjectGuid = "{" + Guid.NewGuid() + "}",
         CodeNamespace = CodeNamespace,
         Tables = tables,
         NewTypes = newTypes
     };
     string template = ReadTemplateFile(projectVesion == ProjectVesion.VS2005 ? PROJECT_FILENAME : (projectVesion == ProjectVesion.VS2008 ? PROJECT_08_FILENAME : PROJECT_10_FILENAME));
     string projectContent = RazorEngine.Razor.Parse(template, model);
     if (!System.IO.Directory.Exists(projectDirectory))
     {
         System.IO.Directory.CreateDirectory(projectDirectory);
     }
     System.IO.File.WriteAllText(Path.Combine(projectDirectory, projectFileName), projectContent, System.Text.Encoding.UTF8);
     return true;
 }
Example #2
0
        public bool GenerateCSProject(string projectDirectory, string[] tables, string[] newTypes, ProjectVesion projectVersion, bool xmlMapping, out string projectFileName)
        {
            string projectGuidText = System.Guid.NewGuid().ToString();
            string compileText = GenerateCompileText(tables, newTypes);
            string embeddedResourceText = xmlMapping ? GenerateEmbeddedResourceText(tables) : string.Empty;

            string projectTemplateFileName = (projectVersion == ProjectVesion.VS2008) ? PROJECT_08_FILENAME : ((projectVersion == ProjectVesion.VS2010) ?  PROJECT_10_FILENAME : PROJECT_FILENAME);
            string projectText = ReadTemplateFile(projectTemplateFileName);
            projectText = projectText.Replace(NAMESPACE_MARK, this.codeNamespace);
            projectText = projectText.Replace("$PROJECTGUID$", projectGuidText);
            projectText = projectText.Replace("$COMPILE$", compileText);
            projectText = projectText.Replace("$EMBEDDEDRESOURCE$", embeddedResourceText);

            if (!System.IO.Directory.Exists(projectDirectory))
            {
                System.IO.Directory.CreateDirectory(projectDirectory);
            }
            projectFileName = string.Format("{0}.csproj", this.codeNamespace);
            System.IO.File.WriteAllText(Path.Combine(projectDirectory, projectFileName), projectText, System.Text.Encoding.UTF8);

            string assemblyInfoText = this.ReadTemplateFile(Path.Combine(PROPERTIES_PATHNAME, ASSEMBLYINFO_FILENAME));
            assemblyInfoText = assemblyInfoText.Replace(NAMESPACE_MARK, this.codeNamespace);
            assemblyInfoText = assemblyInfoText.Replace("$NEWGUIDFORCOM$", System.Guid.NewGuid().ToString());

            string propertyPropertiesDirectory = Path.Combine(projectDirectory, PROPERTIES_PATHNAME);
            if (!System.IO.Directory.Exists(propertyPropertiesDirectory))
            {
                System.IO.Directory.CreateDirectory(propertyPropertiesDirectory);
            }
            System.IO.File.WriteAllText(Path.Combine(propertyPropertiesDirectory, ASSEMBLYINFO_FILENAME), assemblyInfoText, System.Text.Encoding.UTF8);
            return true;
        }