【问题标题】:Is it possible to create a new TFS workspace in PowerShell with Power Tools?是否可以使用 Power Tools 在 PowerShell 中创建新的 TFS 工作区?
【发布时间】:2015-06-27 10:20:39
【问题描述】:

我正在 PowerShell 中构建一个函数,该函数创建一个新的工作区并获取指定目录的最新版本以及一些其他 TFS 和文件系统相关任务。现在我混合使用 PowerTools 和 TFS 程序集来完成工作。看来我可以用 Power Tools 做几乎所有事情,除了创建一个新的工作区。如果不显式加载 Team Foundation 程序集,我还没有弄清楚如何做到这一点。有没有可能?如果有,怎么办?

这就是我现在正在做的事情

#Install required TFS assemblies
"Microsoft.TeamFoundation.Client",
"Microsoft.TeamFoundation.VersionControl.Common",
"Microsoft.TeamFoundation.VersionControl.Client" |
    ForEach-Object { Add-Type -AssemblyName "$_, Version=11.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a" }

#Install TFS PowerTools snappin for basic tasks
If ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.TeamFoundation.PowerShell
}

## Set applicable parameters

#Get the TFS server object
$tfs=Get-TfsServer -Name $tfsName

#Get the version control service object
#This is what I want to do with PowerTools - like a new-item or something
$vcs = $tfs.GetService([type]"Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")

#Create a Workspace parameters object
$workspaceParameters = New-Object Microsoft.TeamFoundation.VersionControl.Client.CreateWorkspaceParameters -ArgumentList $wsName

#Create the Workspace
$tfsw = $vcs.CreateWorkspace($workspaceParameters)

# Add any working folders that you would defined below
$tfsw.Map($tfsLocation, $localFolder)

【问题讨论】:

    标签: powershell tfs tfs-power-tools


    【解决方案1】:

    TFPT 管理单元中唯一的new 命令是New-TfsChangesetNew-TfsShelveset。您是否有不能使用tf.exe workspace /new ...tf.exe workfold ... 的原因?

    【讨论】:

    • 完全没有理由。我是 PoSh 和管理 TFS 的新手。我正在使用的解决方案只是我用自己有限的知识能够找到的解决方案的变体。我被引导到 PowerTools 但另一个用户,但到目前为止,我对 cmdlet 可用的内容有点不知所措。 tf.exe 方法是否有任何先决条件?我需要担心的问题?
    • 同意 TFPT。这是一个好的开始,但它可以做得更多。我真的很怀念没有 Get-TfsPermission cmdlet。我们在构建和测试脚本中大量使用了 tf.exe。主要的先决条件是安装 Visual Studio(或 VS Team Explorer),因为这是安装 tf.exe 的内容。除此之外,您需要知道,为了测试控制台 exe 是否成功,您应该在调用 exe 后检查 $LASTEXITCODE。另外,请注意带有分号的参数。这是一个语句分隔符 PowerShell。
    • 例如,此命令可能会导致 PowerShell tf status . /r /workspace:*;johndoe 出现问题。您需要像这样指定它tf status . /r /workspace:*<backtick-char>;johndoe。或者,如果您使用的是 V3 或更高版本,请使用停止解析运算符,例如tf status . /r --% /workspace:*;johndoe。请注意,使用 --% 时,它会将 PowerShell 置于类似 CMD 的解析模式中,直到行尾。
    猜你喜欢
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2016-04-15
    • 2018-11-11
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多