git命令不在visual studio事件中工作,而是在命令行中工作

时间:2014-11-12 01:07:34

标签: git visual-studio-2013 cmd

我正在尝试运行git log --pretty=format:"%ai %s%n" > "$(SolutionDir)\test.txt",它只返回visual studio输出中的很多行,如:s\<PathToSolutionDir\test.txt。在那行之前,我有另一个git命令运行完美,我的第一个命令是cd /D <PathToProjectWithGit>

在cmd.exe中使用完全相同的命令完全正常。

我已经尝试了不同的方法来转义\,%,^,“,”“,”“”,......

1 个答案:

答案 0 :(得分:0)

Afaik visual studio在后台为后期和后期构建事件调用cmd.exe ...所以对于解决方法,我在应用程序开始时使用了这个:

    Process p = new Process();
    ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
    info.RedirectStandardInput = true;
    info.UseShellExecute = false;
    info.CreateNoWindow = false;
    p.StartInfo = info;
    p.Start();

    using (StreamWriter sw = p.StandardInput)
    {
        if (sw.BaseStream.CanWrite)
        {
            sw.WriteLine("cd /D C:\\your git repo on your local drive");
            sw.WriteLine("git log --pretty=format:"%ai %s" > "C:\\path to dir where log should be placed\\test.txt"
        }
    }

每个sw.WriteLine(&#34;&#34;);可以认为是一行命令行输入 与构建前或构建后事件基本相同......