• 使用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);
                }
            }
  • 相关阅读:
    02-model设计
    01-开发环境搭建
    04-Uwsgi配置启动Nginx虚拟主机配置
    03-MySQL安装与配置
    02-Nginx配置
    01-Nginx安装
    22-注册、登录、验证登录
    21-django-pure-pagination分页
    (二)windows上使用docker
    Docker在windows7上的安装
  • 原文地址:https://www.cnblogs.com/tcli/p/11237940.html
Copyright © 2020-2023  润新知