Update Demo

This commit is contained in:
sunkaixuan 2019-01-21 02:15:32 +08:00
parent 70da57d54f
commit 9464e7d382
2 changed files with 31 additions and 4 deletions

View File

@ -33,6 +33,28 @@ namespace SugarCodeGeneration.Codes
} }
} }
public static void AddRef(string projectName, string refProjectName)
{
var xmlPath = GetSlnPath + @"\" + projectName + @"\" + projectName + ".csproj";
var xml = File.ReadAllText(xmlPath, System.Text.Encoding.UTF8);
if (xml.Contains(refProjectName)) return;
var firstLine = System.IO.File.ReadLines(xmlPath, System.Text.Encoding.UTF8).First();
var newXml = xml.Replace(firstLine, "").TrimStart('\r').TrimStart('\n');
XDocument xe = XDocument.Load(xmlPath);
var root = xe.Root;
XElement itemGroup = new XElement("ItemGroup");
itemGroup.Add(new XElement("Name", refProjectName));
itemGroup.Add(new XElement("ProjectReference", new XAttribute("Include", string.Format(@"..\{0}\{0}.csproj", refProjectName))));
root.Add(itemGroup);
newXml = xe.ToString().Replace("xmlns=\"\"", "");
xe = XDocument.Parse(newXml);
xe.Save(xmlPath);
}
public static void AddCsproj(string classPath, string projectName) public static void AddCsproj(string classPath, string projectName)
{ {
CreateProject(projectName); CreateProject(projectName);
@ -64,7 +86,7 @@ namespace SugarCodeGeneration.Codes
xe.Save(xmlPath); xe.Save(xmlPath);
} }
public static void CreateBLL(string templatePath, string savePath, List<string> tables,string classNamespace) public static void CreateBLL(string templatePath, string savePath, List<string> tables, string classNamespace)
{ {
string template = System.IO.File.ReadAllText(templatePath); //从文件中读出模板内容 string template = System.IO.File.ReadAllText(templatePath); //从文件中读出模板内容
@ -74,7 +96,7 @@ namespace SugarCodeGeneration.Codes
BLLParameter model = new BLLParameter() BLLParameter model = new BLLParameter()
{ {
Name = item, Name = item,
ClassNamespace= classNamespace ClassNamespace = classNamespace
}; };
var result = Engine.Razor.RunCompile(template, templateKey, model.GetType(), model); var result = Engine.Razor.RunCompile(template, templateKey, model.GetType(), model);
var cp = savePath + "\\" + item + "Manager.cs"; var cp = savePath + "\\" + item + "Manager.cs";
@ -96,7 +118,7 @@ namespace SugarCodeGeneration.Codes
{ {
var templatePath = GetCurrentProjectPath + "/Template/Project.txt"; var templatePath = GetCurrentProjectPath + "/Template/Project.txt";
string projectId = Guid.NewGuid().ToString(); string projectId = Guid.NewGuid().ToString();
string project = System.IO.File.ReadAllText(templatePath).Replace("@pid", projectId).Replace("@AssemblyName",name); //从文件中读出模板内容 string project = System.IO.File.ReadAllText(templatePath).Replace("@pid", projectId).Replace("@AssemblyName", name); //从文件中读出模板内容
var projectPath = GetSlnPath + "\\" + name + "\\" + name + ".csproj"; var projectPath = GetSlnPath + "\\" + name + "\\" + name + ".csproj";
var projectDic = GetSlnPath + "\\" + name + "\\"; var projectDic = GetSlnPath + "\\" + name + "\\";
var binDic = GetSlnPath + "\\" + name + "\\bin"; var binDic = GetSlnPath + "\\" + name + "\\bin";

View File

@ -12,7 +12,7 @@ namespace SugarCodeGeneration
{ {
class Program class Program
{ {
//数据库配置 //如果你不需要自定义直接配好数据库连接F5运行项目
const SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer; const SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer;
const string connectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest"; const string connectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest";
@ -71,6 +71,11 @@ namespace SugarCodeGeneration
UpdateCsproj(); UpdateCsproj();
Print("项目解决方案修改成功"); Print("项目解决方案修改成功");
/***添加项目引用***/
Methods.AddRef(bllProjectName2,classProjectName);
Print("引用添加成功");
//如何使用创建好的业务类(注意 SchoolManager 不能是静态的) //如何使用创建好的业务类(注意 SchoolManager 不能是静态的)
//SchoolManager sm = new SchoolManager(); //SchoolManager sm = new SchoolManager();
//sm.GetList(); //sm.GetList();