Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating workspace creation in Team Foundation Server

Tags:

tfs

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?

like image 881
Rowland Shaw Avatar asked Aug 15 '09 08:08

Rowland Shaw


2 Answers

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
like image 148
Preet Sangha Avatar answered Oct 21 '22 15:10

Preet Sangha


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.

like image 27
Andrew Odri Avatar answered Oct 21 '22 15:10

Andrew Odri