Automating workspace creation in Team Foundation S

2020-06-19 18:43发布

Is there any way to easily create a workspace, based on a pre-existing "template" one? ...or some other way of creating workspace on behalf of others?

标签: tfs
4条回答
闹够了就滚
2楼-- · 2020-06-19 19:04

May start do anything with modifying this F# script:

///
/// Creates new local TFS workspace for specified folder and branch conventionally naming locals with server names
/// 
// Install Team Explorer
#r "Microsoft.TeamFoundation.Client"
#r "Microsoft.TeamFoundation.VersionControl.Common"
#r "Microsoft.TeamFoundation.VersionControl.Client"

open Microsoft.TeamFoundation.VersionControl
open Microsoft.TeamFoundation.VersionControl.Common
open Microsoft.TeamFoundation.VersionControl.Client
open Microsoft.TeamFoundation.Client

//change these
let tfsUrl = "http://tfsserver:8080/collection"
let branch ="dev_features"
let folder = "/FeaturesProject/"


//conventions
let workspaceName  = System.Environment.MachineName+"_"+branch
let localFolder = "D:"+folder+branch
let serverFolder = "$/"+folder+branch

// actions
let tfs = TeamFoundationServerFactory.GetServer(tfsUrl)
let vcs = tfs.GetService<VersionControlServer>()
let workspaceParameters = Client.CreateWorkspaceParameters(workspaceName)
workspaceParameters.Folders <- [|  WorkingFolder(serverFolder,localFolder )  |]
workspaceParameters.Location <-   System.Nullable<WorkspaceLocation>(WorkspaceLocation.Local)
let workspace = vcs.CreateWorkspace(workspaceParameters)

//run
workspace  |> ignore
查看更多
别忘想泡老子
3楼-- · 2020-06-19 19:10

You can also copy and paste the workspace mappings from one workspace into another.

  1. Edit the template workspace.
  2. Select the mappings you want to copy.
  3. Press Ctrl+C
  4. Create a new Workspace (or edit an existing one)
  5. Tab into the Working folders grid.
  6. Press Ctrl+V

You can also paste the mappings into Notepad, update them and, copy and paste them back into the workspace editor.

The format you'll see in notepad:

<serverpath>: <localPath>

Example:

$/TeamProj1/Trunk/: C:\TFS\WorkingFolder\
查看更多
ゆ 、 Hurt°
4楼-- · 2020-06-19 19:13

Depending on how much fine grained control you want over the process, I found this PowerShell script to be effective:

"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" }

$tfsUrl = "http://tfsserver:8080/collection"

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsUrl)
$vcs = $tfs.GetService([type]"Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")

$workspaceParameters = New-Object Microsoft.TeamFoundation.VersionControl.Client.CreateWorkspaceParameters -ArgumentList "WorkspaceName"

# Add any specific parameters that you want according to http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.createworkspaceparameters.aspx
# e.g. $workspaceParameters.Comment = ""
# e.g. $workspaceParameters.Computer = ""
# e.g. $workspaceParameters.Location = [Microsoft.TeamFoundation.VersionControl.Common.WorkspaceLocation]::Local

$workspace = $vcs.CreateWorkspace($workspaceParameters)

# Add any working folders that you would defined below
# e.g. $workspace.Map("$/", "C:\ProjectDirectory")

All the parameters that able to be defined are list in this MSDN article: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.createworkspaceparameters.aspx One advantage of this method over tf.exe is that you can explicitly define the workspace location (i.e. server or local), and you have much more control over mappings that are defined at creation.

You should be able to just tweak the appropriate settings and dump this code into any *.ps1 file.

查看更多
▲ chillily
5楼-- · 2020-06-19 19:25

you can create a workspace using a command script using the tf workspace command. Then you can map work folders using the tf workfold command. The workspace command has a /template option

For example:

to create a workspace for someone

tf workspace /new Beta1;jenh

then create a new one based on the template

tf workspace /new /template:Beta1;jenh /server:teamserver2 Beta1;user2

to map a folder:

tf workfold /map $/projects/project_one C:\localproject1 /workspace:Beta1;user2
查看更多
登录 后发表回答