2011-05-27 75 views
1

我有TFS的URL,我有源文件的位置,但我沒有工作區路徑。 如何檢出沒有工作區的文件,或者如何找到某個文件的工作區?團隊基礎服務器,檢出文件沒有工作區

我已經爲TFS中的簽出文件制定瞭解決方案,但在某些情況下,我沒有工作區路徑或名稱。

Dim TeamFoundationServerURL As String ="TFS url" 

Dim TeamProjectCollection As TfsTeamProjectCollection 

'Get project collectio 
TeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(_ 
      New Uri(TeamFoundationServerURL), New UICredentialsProvider()) 

TeamProjectCollection.EnsureAuthenticated() 

Dim Workspace As Workspace 

' get Version Control 
Dim VersionControlServer As VersionControlServer 
VersionControlServer = TeamProjectCollection.GetService(Of VersionControlServer)() 

'location to check out files to: 
Dim WorkspacePath As String = "__I dot have this path ___" 

'find workspace 
Workspace = VersionControlServer.GetWorkspace(WorkspacePath) 

'Check out file 
Workspace.PendEdit(SorceFilePath) 

感謝

回答

3

退房沒有一個工作區是不可能的。因此,如果您需要檢出並且沒有任何工作區信息 - 您應該按需創建一個wokspace。 還有一個選項可以在沒有工作空間VersionControlServer.DownloadFile的情況下下載文件。詳細信息請參見http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.downloadfile(v=vs.80).aspx。它不會被檢出(如「查看」控制檯命令)。

1

我想用我的自動創建功能來做到這一點。我讓它檢出一個版本文件,然後檢查它(在更新它之後)。由於這是構建機器,我沒有可以保證的工作空間映射。

我最終只是檢查,看看我需要的文件是否映射。如果不是,我會映射它。

我知道這不是你要找的解決方案,但我想我會把它扔到那裏讓你考慮。

這裏是我的代碼,它的檢出和在檢查:

private Version GetVersionFromTFS(Workspace currentWorkspace, string versionFileLocation, string versionFileName, out string localVersionPath) 
{ 
    // Make sure we have a map to the version file 
    if (!currentWorkspace.IsServerPathMapped(versionFileLocation)) 
    { 
     // Map the version file to somewhere. 
     currentWorkspace.Map(versionFileLocation, @"C:\temp\BuildVersions" + Guid.NewGuid()); 
    } 

    // Make sure we have the latest from source control. 
    GetRequest getRequest = new GetRequest(new ItemSpec(versionFileLocation + versionFileName,RecursionType.None), VersionSpec.Latest); 
    currentWorkspace.Get(getRequest, GetOptions.Overwrite);   

    localVersionPath = currentWorkspace.GetLocalItemForServerItem(versionFileLocation + versionFileName); 

    string oldVersion = "1.0.0.0"; 
    if (File.Exists(localVersionPath))    
     oldVersion = File.ReadAllText(localVersionPath); 

    return new Version(oldVersion); 
} 

private void UpdateVersionBackToTFS(Workspace currentWorkspace, string versionFileLocation, string versionFileName, Version newVersion, String localVersionPath) 
{ 
    File.WriteAllText(localVersionPath, newVersion.ToString()); 

    WorkspaceCheckInParameters parameters = new WorkspaceCheckInParameters(new[] {new ItemSpec(versionFileLocation + versionFileName, RecursionType.None)}, "***NO_CI*** - Updating Version"); 

    currentWorkspace.CheckIn(parameters); 

} 
相關問題