2012-07-09 62 views
0

我們分支發佈後,有一些需要更新的配置文件。目前,我正在獲取特定(新)分支上所有源代碼的最新版本。這非常耗時且佔用大量磁盤空間。如何使用PowerShell從TFS獲取某些文件?

有沒有辦法搜索/循環通過特定的分支,只獲取符合特定條件的文件?

E.g:

Loop through files under branch on the TFS server 
If file name matches "foo.proj" or file name matches "foo.ini" 
Get latest version of the file 

「獲取」 的部分是容易使用命令行接口來TF(tf get $/project/foo.proj)。我不確定如何在沒有獲得最新版本的情況下遍歷服務器對象。

回答

2

查看TFS PowerToys中的TFS PowerShell Snapin(需要自定義安裝以供選擇)。

在32位PSH實例(Add-PSSnapin Microsoft.TeamFoundation.PowerShell)加載管理單元后,您可以使用:

  • Get-TFSItemProperty一個文件夾上獲得源代碼控制之下的項目清單。
  • Update-TfsWorkspace獲取或更新所有或特定文件/文件夾到您的工作區。

更新:您可以安裝PSH TFS管理單元爲被安裝它通過PowerToys的(見註釋)在這種情況下,這並不侷限於32位PSH例如32位64位自己。

+0

我的印象是安裝TFS PowerToys時默認安裝了TFS PowerShell Snapin。做一個自定義安裝給了我管理單元。此外,使用32位PSH工作。 – Alicia 2012-07-09 22:30:46

+0

它被加載到特定於TFS的Powershell控制檯中,但不是原始的Windows Powershell控制檯。您當然可以更新您的配置文件(在$配置文件中找到)來加載TFS管理單元。 – 2012-07-10 03:23:35

+1

我不得不按照這[鏈接](http://nzbart.blogspot.co.nz/2011/02/getting-tfs-power-tools-2010-working-on.html)中的一個步驟來獲取快照在我的64位控制檯中工作。我還更新了我的配置文件以加載管理單元,以便我不必在每個腳本中都執行此操作(並且它也可供其他用戶使用)。 – Alicia 2012-07-10 04:41:53

1

我到底用這個:

自定義安裝TFS PowerShell管理使用您下載tftp.exe。

添加管理單元中:

if ((Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null) 
{ 
    Add-PSSnapin Microsoft.TeamFoundation.PowerShell 
} 

PowerShell腳本:

param([string] $ServerBranchLocation) 

$tfs=Get-TfsServer -name http://mytfsserver:8080/tfs 
$TfExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" 

$matchFoo = "foofile.foo" 

foreach ($item in Get-TfsChildItem $ServerBranchLocation -r -server $tfs) 
{ 
    if ($item -match $matchFoo) 
    { & "$TFExePath" get $item.ServerItem /force /noprompt } 
} 

我不能找到一種方法使用管理單元中獲得最新的版本,所以我只好用醇'可信tf.exe。

+1

要獲取最新版本,請在不列出版本的情況下使用'Update-TfsWorkspace'(或許使用'-Force'來始終獲取服務器認爲您在工作區中擁有的任何內容)。你可以用'-version'傳遞'tf get'使用的相同版本規範([見msdn](http://msdn.microsoft.com/en-us/library/56f7w6be.aspx))。例如。 'Update-TfsWorkspace -force -version'T''獲取最新版本。 – Richard 2012-07-14 16:54:07

+0

x86 vs x64是什麼? http://geekswithblogs.net/Lance/archive/2009/12/29/program-files-environment-variable-in-powershell.aspx – Kiquenet 2013-04-03 10:42:11