通过powershell在tfs中的分支中签入文件

时间:2015-10-23 20:48:08

标签: powershell tfs tfvc

我有一个带有几个分支的tfs集合,我想通过powershell进行检查。我通常首先通过以下方式连接到集合:Get-tfsserver -Name" tfs:8080 ..."。但我无法在那里指定分支名称。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

要指定分支名称,可以使用$ ServerBranchLocation

定义分支

tfs checkin PowerShell脚本

的示例
param (
    [string]$tfsServer = "TFSServerName",
    [string]$tfsLocation = "$/TFS/Project/serverbranch",
    [string]$localFolder ="c:\scripts",
    [string]$file,
    [string]$checkInComments = "Checked in from PowerShell"
    )
    $clientDll = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.Client.dll"
    $versionControlClientDll = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.VersionControl.Client.dll"

    #Load the Assemblies
    [Reflection.Assembly]::LoadFrom($clientDll)
    [Reflection.Assembly]::LoadFrom($versionControlClientDll)
    [Reflection.Assembly]::LoadFrom($versionControlCommonDll)

    #Set up connection to TFS Server and get version control
    $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer)
    $versionControlType = [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]
    $versionControlServer = $tfs.GetService($versionControlType)

    #Create a "workspace" and map a local folder to a TFS location
    $workspace = $versionControlServer.CreateWorkspace("PowerShell Workspace",$versionControlServer.AuthenticatedUser)
    $workingfolder = New-Object Microsoft.TeamFoundation.VersionControl.Client.WorkingFolder($tfsLocation,$localFolder)
    $workspace.CreateMapping($workingFolder)
    $filePath = $localFolder + "\" + $file

    #Submit file as a Pending Change and submit the change
    $workspace.PendAdd($filePath)
    $pendingChanges = $workspace.GetPendingChanges()
    $workspace.CheckIn($pendingChanges,$checkInComments)

    #Delete the temp workspace
    $workspace.Delete()

答案 1 :(得分:0)

PowerShell是:



# Load TFS Client Assembly
[Reflection.Assembly]::Load('Microsoft.TeamFoundation.VersionControl.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')

#Connect to TFS Server
[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer("https://name.visualstudio.com/defaultcollection")

#Add File
#Adds files and folders from a location in the local file system to a version control server for Team Foundation.

$WorkstationType = [Microsoft.TeamFoundation.VersionControl.Client.Workstation]
$WorkspaceInfo = $WorkstationType::Current.GetLocalWorkspaceInfo("localFolderForBranch")



# Get Collection
$Collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($WorkspaceInfo.ServerUri)
$Collection.EnsureAuthenticated()

# Get Workspace.
$Global:Workspace = $WorkspaceInfo.GetWorkspace($Collection)

#Check in new file

$pendingChanges = $workspace.GetPendingChanges() 
$Comment = "checkin branch....."
$workspace.CheckIn($pendingChanges,$Comment)




还要检查此博客中Windows PowerShell部分中的版本控制步骤,以获取详细信息:http://blogs.technet.com/b/heyscriptingguy/archive/2012/12/28/protect-your-powershell-scripts-with-version-control.aspx