我只想用 powershell 检查一个路径,并在一分钟后在 Team Foundation Server 上检查这个路径。
我怎样才能做到这一点?
我已经在我的服务器上安装了 tfs 电动工具。
我只想用 powershell 检查一个路径,并在一分钟后在 Team Foundation Server 上检查这个路径。
我怎样才能做到这一点?
我已经在我的服务器上安装了 tfs 电动工具。
你不需要电动工具。只需使用带有 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
}
}
这是我的解决方案:
$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.exe 路径别名 tf。因此,只需在此处使用 tf.exe 命令行参考,如果您正确安装了 powershell 命令行开关,所有这些都应该可以工作。
不过,您应该确保您的 powershell 已使用此命令安装它们
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
如果您尝试在同一命令中处理多个文件而不拾取其他文件或循环访问它们,则另一种选择是使用通配符。
tf.exe undo AssemblyInfo* /recursive
tf.exe checkout AssemblyInfo* /recursive
#changes files
tf.exe checkin AssemblyInfo* /recursive