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);
                }
            }
  • 相关阅读:
    在线漏洞检测网站
    渗透测试工具库
    端口利用解析
    Linux安全脚本
    Linux常见系统故障
    Oracle
    Redis和MongoDB区别
    MHA在监控和故障转移时都做了什么
    Oracle 11g Dataguard参数详解
    Oracle
  • 原文地址:https://www.cnblogs.com/tcli/p/11237940.html
Copyright © 2011-2022 走看看