如何在PowerShell中编写脚本以运行Microsoft Visual Studio 2010 TFS;获取最新版本;? 是否有人知道如何编写PopeScript脚本来自动化Team Foundation Server的“获取最新版本”功能?

如何在PowerShell中编写脚本以运行Microsoft Visual Studio 2010 TFS;获取最新版本;? 是否有人知道如何编写PopeScript脚本来自动化Team Foundation Server的“获取最新版本”功能?,powershell,tfs,Powershell,Tfs,我试过几个例子,但没有一个奏效 这是到目前为止我的代码: #Load Reference Assemblies [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client") [v

我试过几个例子,但没有一个奏效

这是到目前为止我的代码:

#Load Reference Assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")  
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")  
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")

Function Get-TFSLatestFromVersionControls
{
param
(
#FQDN to SCCM Server
[Parameter(Mandatory=$true)][string]$YourServerPath = "$/DEV",
[Parameter(Mandatory=$true)][string]$YourLocalPath = "C:\Project\DEV",
[Parameter(Mandatory=$false)][string]$tfsCollectionUrl = "http://10.0.10.200:8080/tfs/collection"
)

#Delete the old local copy
if((Test-Path -Path ($YourLocalPath)) -eq 1 )
{
    Remove-Item -Path $YourLocalPath -Recurse
    New-Item -Path $YourLocalPath -Type directory
Read-Host -Prompt "Delete the old local copy"
}


#Get Team Project Collection
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl)

#enter a path to your tfs server
$tfsServer = $tfsCollectionUrl
 # get an instance of TfsTeamProjectCollection
$tfs=get-tfsserver $tfsServer
# get an instance of VersionControlServer
$vCS = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$TeamProject = $YourServerPath.Remove(0,2)
$tfsProject = $vcs.GetTeamProject($TeamProject)


$workspace = $vcs.GetWorkspace($YourLocalPath)
if($workspace -eq $null)
{
    $vcs.DeleteWorkspace("TFS-"+$env:COMPUTERNAME,$env:USERNAME)
    $workspace = $vcs.CreateWorkspace("TFS-"+$env:COMPUTERNAME, $env:USERNAME)
Read-Host -Prompt "Delete the old workspace"
}

$workspace.Map($YourServerPath, $YourLocalPath)

$workspace.Get([Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest ,[Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite)
Read-Host -Prompt "Get Latest"
}

实现这一点的最简单方法是安装Patrick提到的,然后只需使用“
Update TfsWorkspace
”命令即可获得最新版本。

如果您想通过TFS API获取最新版本,请参阅下面的代码以了解详细信息:

$uri = "http://tfsurl:8080/tfs/collectionname/";
$workspacename = "workspacename"
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri)
$vcs = $tfs.GetService("Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")
$workspaces = $vcs.QueryWorkspaces($workspacename,"","")
$workspace = $workspaces | Select-Object -First 1
$workspace.Get();

实现这一点的最简单方法是安装Patrick提到的,然后只需使用“
Update TfsWorkspace
”命令即可获得最新版本。

如果您想通过TFS API获取最新版本,请参阅下面的代码以了解详细信息:

$uri = "http://tfsurl:8080/tfs/collectionname/";
$workspacename = "workspacename"
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri)
$vcs = $tfs.GetService("Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")
$workspaces = $vcs.QueryWorkspaces($workspacename,"","")
$workspace = $workspaces | Select-Object -First 1
$workspace.Get();

可能的重复没有重复没有解决问题你试过写代码吗?StackOverflow不是代码编写服务。向我们展示您尝试了什么,我们也许能够提出解决方案。我已经编辑了我的MyPar,您可以使用,打开Windows PuthSeam控制台,然后从VisualStudio加载Team Foundation CMDLead,然后可以使用版本控制。更多详细信息请参考可能的副本否副本无法解决问题您是否尝试过编写任何代码?StackOverflow不是代码编写服务。向我们展示您尝试了什么,我们也许能够提出解决方案。我已经编辑了我的MyPar,您可以使用,打开Windows PuthSeam控制台,然后从VisualStudio加载Team Foundation CMDLead,然后可以使用版本控制。详情请参阅