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);
                }
            }
  • 相关阅读:
    将本地文件夹添加到Git仓库
    flex调用Webservice(一)
    经典的sql
    打印相关
    reporting services订阅
    关于TabIndex
    试题(一)
    试试用手机
    2010.07.13_19:30
    基础知识
  • 原文地址:https://www.cnblogs.com/tcli/p/11237940.html
Copyright © 2011-2022 走看看