I have below PowerShell Script written to check-out the files in TFS by referring the path mentioned in the TFS Path.txt file.
#$TFSCheckoutExe="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe"
$TFSFilePaths=Get-Content "$PSScriptRoot\TFS Path.txt"
$TFSCheckoutExe="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe"
$visualStudiopath = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer'
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Common.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Client.dll"
Add-type -path "$visualStudiopath\Microsoft.TeamFoundation.ProjectManagement.dll"
Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Build.Common.dll"
#TFS Collection Path
$sourceLocation = "http://vwmaztfsapp:8080/tfs/MatchCollection"
#Creating TFS Object
$tfsCollectionUrl = New-Object System.URI($sourceLocation);
$tfsCollection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $tfsCollectionUrl
$VersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
$latest = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest
$recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
Foreach($TFSFilePath in $TFSFilePaths)
{
&$TFSCheckoutExe checkout $TFSFilePath | Out-Null
}
I am getting an error while trying to check-out the file in TFS? (screenshot below)
Can anyone please let me know how can I resolve this error, what am I missing?
In order to checkout a file, you first need a workspace mapping. It must be a server mapping to check out a file, local workspaces don't have a checkout option.
Then map your local folder to a server in the TFVC reporitory
Then call
get
orcheckout
. I'm not 100% you can checkout a file without getting it first.You can accomplish the same thing without depending on
tf.exe
in pure powershell. You can find a complete example in my TFVC tasks for Azure Pipelines. You still need a local workspace for this to work:The code to find a workspace from the local workspace cache can be found in the shared module:
This code should contain enough information to build a new workspace too if you'd want that.