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);
                }
            }
  • 相关阅读:
    如何:通过对字符串应用 HTML 编码在 Web 应用程序中防止脚本侵入
    ref和out的区别?
    debug版本和release版本的区别?
    Ninject依赖注入——构造函数的注入
    WCF入门简单教程(图文) VS2010版
    WCF学习笔记(一)
    WinRt BottomAppBar
    windows 8.1 MessageDialog
    sqlServer学习2-sql脚本说明
    sqlServer学习1-sql脚本
  • 原文地址:https://www.cnblogs.com/tcli/p/11237940.html
Copyright © 2011-2022 走看看