Freigeben über


Recreating the TFVC Team Project Folder

TF.exe makes it easy to destroy a TFVC team project folder, but if you do it's not as easy to recreate it.

You can destroy all TFVC data in a team project by running  tf.exe destroy $/<projectName>

Then if you try to navigate TFVC in a web browser, you'll see an error like this:

TFS.WebApi.Exception: The items requested either do not exist on the server at the specified versions, or you do not have permission to access them.

If you decide you want to add back the team project folder, you cannot use tf.exe to do it.  There is no cmdline equivalent to recreate that team project folder.  If you try tf.exe add <projectName> you'll see an error like this:

TF10169: Unsupported pending change attempted on team project folder $/projectName.  Use the Project Creation Wizard in Team Explorer to create a project or the Team Project deletion tool to delete one.

That error message isn't helpful when you already have a team project with this name and only the TFVC project folder is missing.

To fix this, you'll need to use the TFS client OM.  Here is a Powershell script that will recreate the team project folder.  You will need to run this on a machine that has Visual Studio installed. The running user must also have administrator permissions to your TFS collection.

Note that this script will recreate the project folder, but it will not recreate the build and lab templates that are created when a project is created but were destroyed when they ran TF destroy. If you want those templates, you can copy them from any existing project.

You will need to update the $accountName and $projectName variables below. If you install Visual Studio in a non-default path, you’ll also need to update the $path and $path2 variables.  $accountName could be a VSTS account URL or an on-premises TFS Collection URL.

$accountName = "https://<accountName>.visualstudio.com"

$projectName = "<projectName>"

$path = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer"

$path2="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies"

Add-Type -Path "$path\Microsoft.TeamFoundation.Client.dll"

Add-Type -Path "$path\Microsoft.TeamFoundation.VersionControl.Client.dll"

Add-Type -Path "$path\Microsoft.TeamFoundation.VersionControl.Common.dll"

Add-Type -Path "$path2\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"

Add-Type -Path "$path\Microsoft.VisualStudio.Services.Client.dll"

$tpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($accountName)

$vc = $tpc.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])

$options = New-Object Microsoft.TeamFoundation.VersionControl.Client.TeamProjectFolderOptions($projectName)

$vc.CreateTeamProjectFolder($options)