Automate workspace creation in Team Foundation Server

Is there a way to easily create a workspace based on an existing “template”? ... or in some other way to create a workspace on behalf of others?

+5
source share
4 answers

you can create a workspace using the script command using the tf workspace command . You can then map the working folders using the tf workfold command . The workspace command has the / template option

For example:

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 display the folder:

tf workfold /map $/projects/project_one C:\localproject1 /workspace:Beta1;user2
+7
source

, , PowerShell script :

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

, , MSDN: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.createworkspaceparameters.aspx. tf.exe ( ), , .

*.ps1.

+2

.

  1. .
  2. , .
  3. Ctrl + C
  4. ( )
  5. .
  6. Ctrl + V

, , .

, :

<serverpath>: <localPath>

:

$/TeamProj1/Trunk/: C:\TFS\WorkingFolder\
0

- 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
0

All Articles