2015-09-12 33 views

回答

1

经过长时间的搜索(在非常糟糕的msdn文档中关于tf.exe命令的小时和小时!),我找到了获取信息的方法!

首先,您必须使用tf.exe workfold c:\your\path命令找出文件夹位于哪个工作区中。该命令的输出类似的东西:

================================================================ 
Workspace : NameOfYourWorkspace (John Doe) 
Collection: https://tfs.yourtfs.com/tfs/defaultcollection 
$/: C:\your\path 

然后你要提取“工作区”(注:我们真的不知道为什么这里的tf.exe命令被全球接受的格式不输出工作区tf.exe命令即“工作区名;所有者”,因此应适应)和“收集”的数据在tf.exe workspaces /format:detailed命令来使用它,这样的:

tf.exe" workspaces /format:detailed /collection:"https://tfs.yourtfs.com/tfs/defaultcollection" "NameOfYourWorkspace;John Doe" 

命令输出类似的东西:

=============================================== 
Workspace : NameOfYourWorkspace 
Owner  : John Doe 
Computer : YOU_COMPUTER 
Comment : 
Collection : yourtfs.com\DefaultCollection 
Permissions: Private 
Location : Local 
File Time : Current 

Working folders: 
$/: C:\your\path 

,我想这里最重要的数据是

我已经写了一个小PowerShell脚本Location : Local(或Server),如果它可能是没有多大用处的人来提取数据在输出使用它们:

function ExtractData($text, $key) 
{ 
    $pattern = "^$key *: *(.+)$" 
    $filteredText= $text | Select-String $key 
    $found = $filteredText -match $pattern 
    if ($found) { 
     return $matches[1] 
    } 
    exit 1 
} 

$currentWorkspaceData = (& "$env:VS120COMNTOOLS..\IDE\tf.exe" workfold .) 
$workspace = ExtractData $currentWorkspaceData "Workspace" 
$found = $workspace -match "^(.+) \((.+)\)$" 
if (!$found) { 
    exit 1 
} 
$workspace = $matches[1] + ";" + $matches[2] 

$collection = ExtractData $currentWorkspaceData "Collection" 

$location=(ExtractData (& "$env:VS120COMNTOOLS..\IDE\tf.exe" workspaces /format:detailed /collection:$collection $workspace) "Location") 
$localServer = $location -eq "Local" 
if($localServer) 
{ 
    Write-Host "Local!!!" 
} 
else 
{ 
    Write-Host "Server!!!" 
} 

该脚本只给出当前文件夹的答案,但可以很容易地适应...

相关问题