我需要从 TFS 获取修订号,如果我从进程运行 tf.exe,进程会停止。如果我从命令提示符运行相同的命令,它可以工作吗?
int revision;
var repo = "path to repo"
var psi = new ProcessStartInfo("cmd", @"/c ""C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe"" properties $/MYProject -recursive /version:W")
{
UseShellExecute = false,
ErrorDialog = false,
CreateNoWindow = false,
WorkingDirectory = repo,
RedirectStandardOutput = true,
RedirectStandardError = true
};
using (var p = Process.Start(psi))
{
p.WaitForExit();
if (p.ExitCode != 0)
{
using (var standardError = p.StandardError)
{
Console.WriteLine(standardError.ReadToEnd());
}
}
else
{
using (var standardOutput = p.StandardOutput)
{
revision = int.Parse(standardOutput.ReadToEnd());
}
}
}
编辑:
我做了这个,工作,我应该去吗?
public int GetLatestChangeSet(string url, string project)
{
var server = new TeamFoundationServer(new Uri(url));
var version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
var items = version.GetItems(string.Format(@"$\{0}", project), RecursionType.Full);
return items.Items.Max(i => i.ChangesetId);
}