我用這個
/// <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;
}
}
這我怎麼執行命令後TF命令
/// <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 2012-02-29 18:52:16
我們可以通過用戶名和密碼下面的tfs連接 'var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer)); tfs.Connect(ConnectOptions.None);' bcoz在將我的網頁部署到IIS服務器後,我無法獲取tfs的詳細信息,但對於本地主機,我能夠獲取相同網頁的tfs詳細信息。 我越來越低err Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException:TF30063:您無權訪問http:// tfsserver:8080/tfs/mycollection。在Microsoft.TeamFoundation.Client.TfsConnection.ThrowAuthorizationException(異常e) – picnic4u 2012-10-22 16:02:31
@ picnic4u可能最好提出一個新的問題。 – DaveShaw 2012-10-22 17:17:38