che uso comando tf segue per questo
/// <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
}
dopo l'esecuzione il parsing l'uscita di questo comando per ottenere changeset numero
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;
}
}
questo modo ho eseguito il comando
/// <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;
}
Non è un modo efficiente ma è ancora una soluzione che funziona in TFS 2008, spero che questo aiuti.
sembra VersionControlServer ha anche un metodo GetLatestChangesetId. È molto più breve :-) – tbaskan
possiamo passare il nome utente e pwd per la seguente connessione tfs 'var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection (nuovo Uri (tfsServer)); tfs.Connect (ConnectOptions.None); ' bcoz dopo aver distribuito le mie pagine Web al server IIS non riesco ad ottenere i dettagli di tfs ma per localhost sono in grado di ottenere i dettagli di tfs per le stesse pagine web. mi trovo sotto err Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: non sei autorizzato ad accedere a http: // tfsserver: 8080/tfs/mycollection. a Microsoft.TeamFoundation.Client.TfsConnection.ThrowAuthorizationException (Exception e) – picnic4u
@ picnic4u probabilmente è meglio sollevare una nuova domanda per questo. – DaveShaw