【发布时间】:2012-11-21 01:56:12
【问题描述】:
我只想用 powershell 签出一个路径,并在一分钟后在 Team Foundation Server 上签入该路径。
我该怎么做?
我已经在我的服务器上安装了 tfs 电动工具。
【问题讨论】:
标签: powershell tfs powershell-2.0
我只想用 powershell 签出一个路径,并在一分钟后在 Team Foundation Server 上签入该路径。
我该怎么做?
我已经在我的服务器上安装了 tfs 电动工具。
【问题讨论】:
标签: powershell tfs powershell-2.0
您不需要电动工具。只需使用带有 TFS 团队资源管理器的 Visual Studio 附带的 tf.exe 命令行实用程序。 tf edit <file> /noprompt 签出和tf checkin <file> /comment:$comment /noprompt 签入。查看 tf.exe 上的命令行用法以获取更多信息 tf /? 和 tf checkin /?。您将需要使用 tf.exe 的路径配置您的 PowerShell 会话。这通常由 VS vars 批处理文件完成。但是您应该能够像这样简单地添加到路径中:$PATH += "${VS110COMNTOOLS}..\Ide"。
【讨论】:
这是一个检查是否安装了管理单元的函数。如果您安装了 powertools,它会使用它,否则,它会使用命令行工具 tf.exe
function checkout-file([string] $file)
{
"Checking out $file"
if ((Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue
if ((Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
#try to check out the code using command line tf.exe
&"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe" checkout $file | Out-Null
}
else{
#checkout the file using snapin
Add-TfsPendingChange -Edit $file | Out-Null
}
}else{
#checkout the file using snapin
Add-TfsPendingChange -Edit $file | Out-Null
}
}
【讨论】:
$cmntools = Get-ChildItem -Path 'Env:\VS*COMNTOOLS' | Sort-Object -Property 'Name' -Descending | %{ ($_.Value.replace('\Tools\','\IDE\TF.exe') ) }
这是我的解决方案:
$tf = &"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe" checkout C:\setup\folder /recursive
$tf | Out-null
【讨论】:
如果您为 powershell 安装了电动工具命令行开关。您不需要像 Kieth 提到的那样的路径,命令行的一部分将 tf 别名为完整的 tf.exe 路径。因此,只需使用 tf.exe 命令行参考 here,如果您正确安装了 powershell 命令行开关,所有这些都应该可以工作。
您应该确保您的 powershell 已使用此命令安装它们
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
【讨论】:
Add-TfsPendingChange 和 New-TfsChangeset。 :-)
如果您尝试在同一命令中处理多个文件而不选择其他文件或循环访问它们,则另一种选择是使用通配符。
tf.exe undo AssemblyInfo* /recursive
tf.exe checkout AssemblyInfo* /recursive
#changes files
tf.exe checkin AssemblyInfo* /recursive
【讨论】: