Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将分支的名称输入到代码中_C#_Git_Visual Studio - Fatal编程技术网

C# 将分支的名称输入到代码中

C# 将分支的名称输入到代码中,c#,git,visual-studio,C#,Git,Visual Studio,我有一个关于将分支名称作为字符串传递给代码的问题 因此,我们使用的是git存储库,分支编号也指放置构建的暂存环境。也就是说,如果我的分支是001,那么我的url是001.test.myapplication.com 我正在编写在分支的暂存环境中执行的自动化测试。我的问题是,是否可以将分支编号传递给我的代码,这样我就可以将其作为我要测试的URL的一部分 我正在使用visual studio 2017、selenium和specflow。通常的方法是生成一个包含此信息的C#文件,作为构建步骤的一部分

我有一个关于将分支名称作为字符串传递给代码的问题

因此,我们使用的是git存储库,分支编号也指放置构建的暂存环境。也就是说,如果我的分支是001,那么我的url是001.test.myapplication.com

我正在编写在分支的暂存环境中执行的自动化测试。我的问题是,是否可以将分支编号传递给我的代码,这样我就可以将其作为我要测试的URL的一部分


我正在使用visual studio 2017、selenium和specflow。

通常的方法是生成一个包含此信息的C#文件,作为构建步骤的一部分

这里已经有几个很好的答案:


事实上,我找到了一个非常有效的解决方案。因此,在将来,其他人也可以使用它,如果他们需要的话

        ProcessStartInfo startInfo = new ProcessStartInfo("git.exe");

        startInfo.UseShellExecute = false;
        startInfo.WorkingDirectory = "dir Here";
        startInfo.RedirectStandardInput = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.Arguments = "rev-parse --abbrev-ref HEAD";

        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();

        string branchname = process.StandardOutput.ReadLine();

试图从git命令行获取输出?这对我来说非常有效。我建议将流程工作包装在using语句中。