Phi*_*ppe 5 version-control powershell tfs command-line
有没有办法确定现有 tfs 工作区中映射的特定文件夹是本地工作区还是服务器工作区?
tf.exe我最感兴趣的是使用命令或API 的答案powershell(但不是使用 GUI!)。
经过长时间的搜索(在关于该命令的非常糟糕的 msdn 文档中花费了数小时tf.exe!),我找到了获取信息的方法!
首先,您必须使用该tf.exe workfold c:\your\path命令找出该文件夹位于哪个工作区中。该命令输出类似这样的内容:
================================================================
Workspace : NameOfYourWorkspace (John Doe)
Collection: https://tfs.yourtfs.com/tfs/defaultcollection
$/: C:\your\path
Run Code Online (Sandbox Code Playgroud)
然后你必须提取“工作空间”(注意:我们真的不知道为什么这里命令tf.exe不以命令在任何地方接受的格式输出工作空间,tf.exe即“WorkspaceName;Owner”,因此应该进行调整!) “收集”数据以在命令中使用它tf.exe workspaces /format:detailed,如下所示:
tf.exe" workspaces /format:detailed /collection:"https://tfs.yourtfs.com/tfs/defaultcollection" "NameOfYourWorkspace;John Doe"
Run Code Online (Sandbox Code Playgroud)
该命令输出类似这样的内容:
===============================================
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
Run Code Online (Sandbox Code Playgroud)
我在这里想要的重要数据是Location : Local(或Server)
我写了一个小 powershell 脚本,如果有人提取输出中的数据来使用它们没有什么用处的话:
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!!!"
}
Run Code Online (Sandbox Code Playgroud)
该脚本仅给出当前文件夹的答案,但可以轻松调整......