Я использую следующую команду тс для этого
/// <summary>
/// Return last check-in History of a file
/// </summary>
/// <param name="filename">filename for which history is required</param>
/// <returns>TFS history command</returns>
private string GetTfsHistoryCommand(string filename)
{
//tfs history command (return only one recent record stopafter:1)
return string.Format("history /stopafter:1 {0} /noprompt", filename); // return recent one row
}
после выполнения я анализирую вывод этой команды, чтобы получить набор изменений номера
using (StreamReader Output = ExecuteTfsCommand(GetTfsHistoryCommand(fullFilePath)))
{
string line;
bool foundChangeSetLine = false;
Int64 latestChangeSet;
while ((line = Output.ReadLine()) != null)
{
if (foundChangeSetLine)
{
if (Int64.TryParse(line.Split(' ').First().ToString(), out latestChangeSet))
{
return latestChangeSet; // this is the lastest changeset number of input file
}
}
if (line.Contains("-----")) // output stream contains history records after "------" row
foundChangeSetLine = true;
}
}
Это, как я выполнить команду
/// <summary>
/// Executes TFS commands by setting up TFS environment
/// </summary>
/// <param name="commands">TFS commands to be executed in sequence</param>
/// <returns>Output stream for the commands</returns>
private StreamReader ExecuteTfsCommand(string command)
{
logger.Info(string.Format("\n Executing TFS command: {0}",command));
Process process = new Process();
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = _tFPath;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.Arguments = command;
process.StartInfo.RedirectStandardError = true;
process.Start();
process.WaitForExit(); // wait until process finishes
// log the error if there's any
StreamReader errorReader = process.StandardError;
if(errorReader.ReadToEnd()!="")
logger.Error(string.Format(" \n Error in TF process execution ", errorReader.ReadToEnd()));
return process.StandardOutput;
}
Неэффективный способ, но все же решение, которое работает в TFS 2008, надеюсь, что это поможет.
кажется VersionControlServer также имеет метод GetLatestChangesetId. Это намного короче :-) – tbaskan
мы можем передать имя пользователя и pwd для ниже tfs-соединения 'var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection (новый Uri (tfsServer)); tfs.Connect (ConnectOptions.None); ' bcoz после развертывания моих веб-страниц на сервере IIS, я не могу получить данные tfs, но для localhost я могу получить данные tfs для тех же веб-страниц. i m становится ниже err Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: у вас нет доступа к http: // tfsserver: 8080/tfs/mycollection. в Microsoft.TeamFoundation.Client.TfsConnection.ThrowAuthorizationException (исключение e) – picnic4u
@ picnic4u, вероятно, лучше всего поднимает новый вопрос для этого. – DaveShaw