zoukankan      html  css  js  c++  java
  • 使用Git获取最新代码并使用msbuild编译项目

    因部署需要获取最新代码并编译项目,使用Git本身的命令即可

    static void GitPull(string codePath)
            {
                if (System.IO.File.Exists(codePath))
                {
                    FileInfo fi = new FileInfo(codePath);
                    Process process = new Process();
                    process.StartInfo.FileName = "cmd.exe";
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;
                    process.StartInfo.RedirectStandardInput = true;
    
                    process.OutputDataReceived += Process_OutputDataReceived;
                    process.ErrorDataReceived += Process_ErrorDataReceived;
    
                    process.StartInfo.Arguments = fi.DirectoryName;
                    process.Start();
    
                    Console.WriteLine("Getting new codes form git at {0} ", process.StartTime);
                    Console.WriteLine("");
    
                    process.StandardInput.WriteLine(@"cd " + fi.DirectoryName);
                    process.StandardInput.WriteLine(fi.DirectoryName.Substring(0, 2));
                    process.StandardInput.WriteLine(@"git pull");
                    process.StandardInput.Close();
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    process.WaitForExit();
                    process.CancelOutputRead();
                    process.CancelErrorRead();
                    Console.WriteLine("finished update codes!");
                }
                else
                {
                    Console.WriteLine("Invalid code path,please check the settings ,press any key to exist!");
                    Console.Read();
                    Environment.Exit(0);
                }
            }

    编译项目代码

     static void BuildProject(string projectPath)
            {
                if (System.IO.File.Exists(projectPath))
                {
                    string msbuildPath = ConfigurationManager.AppSettings["MSBuildPath"];
    
                    DirectoryInfo di = new DirectoryInfo(msbuildPath);
                    if (di.Exists == false)
                    {
                        Console.WriteLine("msbuild path is invalid!");
                        Console.Read();
                        return;
                    }
                    FileInfo fi = new FileInfo(projectPath);
                    Process process = new Process();
                    process.StartInfo.FileName = "cmd.exe";
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;
                    process.StartInfo.RedirectStandardInput = true;
    
                    process.OutputDataReceived += Process_OutputDataReceived;
                    process.ErrorDataReceived += Process_ErrorDataReceived;
    
                    process.StartInfo.Arguments = fi.DirectoryName;
                    process.Start();
    
                    Console.WriteLine("Getting new codes form git at {0} ", process.StartTime);
                    Console.WriteLine("");
    
                    process.StandardInput.WriteLine(@"cd " + msbuildPath);
    
                    process.StandardInput.WriteLine(di.Root.Name.Replace("\", ""));
                    process.StandardInput.WriteLine(@"MSBuild.exe {0} -property:Configuration=Release -t:rebuild",projectPath);
                    process.StandardInput.Close();
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    process.WaitForExit();
                    process.CancelOutputRead();
                    process.CancelErrorRead();
                    Console.WriteLine("finished build project!");
                }
                else
                {
                    Console.WriteLine("Invalid code path,please check the settings ,press any key to exist!");
                    Console.Read();
                    Environment.Exit(0);
                }
            }
  • 相关阅读:
    java程序后台报错java.net.SocketException: Too many open files
    linux中,查看某个命令是来自哪个RPM包或者是通过哪个RPM包安装的
    Oracle卸载之linux快速卸载rac脚本-一键卸载
    40个DBA日常维护的SQL脚本
    Oracle SQL开发 之 Select语句完整的执行顺序
    Oracle开发 之 主-外键约束FK及约束的修改
    drop user 报错ora-00604
    oracle Bug 4287115(ora-12083)
    Ora-1157 ora-1110错误解决案例一枚
    rac库grid目录权限(6751)导致数据库宕机案例 此方法仅用于紧急救助
  • 原文地址:https://www.cnblogs.com/tcli/p/11237940.html
Copyright © 2011-2022 走看看