theChampion
theChampion

Reputation: 4457

Remove TFS Connection From Solution

How to make solution as clean copy without mapping to TFS ? The problem is that this message shows when I am trying to open it. I want to open it as normal without TFS connection.

enter image description here

Upvotes: 103

Views: 114935

Answers (7)

Hamid Shahid
Hamid Shahid

Reputation: 4616

Edit the solution file and remove the following section from it. It won't be the same but will be similar.

Note:To edit the solution file go to the project folder then open the YouSolutionName.sln file with notepad.

GlobalSection(TeamFoundationVersionControl) = preSolution
    SccNumberOfProjects = 2
    SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
    SccTeamFoundationServer = <YourTFSURL>
    SccLocalPath0 = .
    SccProjectUniqueName1 = .
    SccLocalPath1 = .
EndGlobalSection

Upvotes: 48

Tabish Usman
Tabish Usman

Reputation: 3250

To completely remove TFS source control binding follow these two steps:

  1. Go to your solution's folder, find and delete all files with *.vssscc and *.vspscc extensions.
  2. Open your solution's .sln file in Notepad, and find & remove the GlobalSection(TeamFoundationVersionControl) section.

More details on reference Link

Upvotes: 232

David at HotspotOffice
David at HotspotOffice

Reputation: 758

I just inherited a collection of TeamFoundation projects following an M&A buyout and tech transfer. There were like 30+ solutions and a buttload of *.vssscc and *.vspscc files.

Based on everyone's input above, I wrote a PowerShell function to recurse a specified root folder, delete the files, then edit the solution files to remove the TeamFoundationVersionControl section.

Usage is Remove_TFSfiles "pathname" $booleanflag.

To see what files would be affected, use $false (uses -whatif):

Remove_TFSfiles "C:\MyDevFolder" $false

To actually delete those files, use $true:

Remove_TFSfiles "C:\MyDevFolder" $true

Here's the function:

Function Remove_TFSfiles { 
    param(
        [string]$FolderName = $(throw "-FolderName is required."),
        [bool]$RemoveFiles = $(throw "-RemoveFiles (either $true or $false) is required.")
    )
    $TFSExtensions = '*.vspscc', '*.vssscc'                          

    if ($RemoveFiles) {
        Get-ChildItem -path $FolderName -force -include $TFSExtensions -Recurse | Remove-Item -Force        
        # Now iterate through any solution files, and whack the TeamFoundationVersionControl section
        Get-ChildItem -Path $FolderName -Filter "*.sln" -Recurse | ForEach-Object {
            $slnFilename = $_.Fullname
            Write-Host -NoNewline "Editing $slnFilename... "
            $File = Get-Content $slnFilename -raw
            $Filestr = [regex]::escape("" + $File + "")
            # The regex escapes must themselves be meta-escaped, therefore "\(" becomes "\\" + "\(" = "\\\(". Did I mention I hate regex?
            $Result = $Filestr -replace "\\tGlobalSection\\\(TeamFoundationVersionControl\\\).*?EndGlobalSection\\r\\n", ""
            $result = [regex]::unescape($result)
            Set-ItemProperty $slnFilename IsReadOnly $false
            $result | Set-Content $slnFilename 
            Write-Host "Done"
        }
        Write-Host -f red "Finished actually removing files and editing *.sln files"
    }
    else {
        Get-ChildItem -path $FolderName -force -include $TFSExtensions -Recurse | Remove-Item -WhatIf
        Write-Host -f green "Finished pretending to remove files"
        # Now iterate through any solution files, and whack the TeamFoundationVersionControl section
        Get-ChildItem -Path $FolderName -Filter "*.sln" -Recurse | ForEach-Object {
            $slnFilename = $_.Fullname 
            Write-Host "Not Editing $slnFilename"
        }
    }
}

Upvotes: 3

Abubakar Ahmad
Abubakar Ahmad

Reputation: 2593

Most of the answers provided a solution, but I would rather use a solution provided by Visual Studio 2017.

On the Menu bar of Visual Studio, go to Team and select Disconnect from Team Foundation Server. That's it.

Upvotes: 5

dwillis77
dwillis77

Reputation: 433

I don't have enough reputation to comment, but just wanted to add that Tabish's solution does in fact work correctly to completely remove the solution from source control, especially when the TFS server is not reachable for one reason or another (e.g. you downloaded a project that the author did not remove from their own source control before uploading).

However, to completely remove all traces of source control from the project and avoid the warnings that are noted in the other comments to that answer (e.g. "The mappings for the solution could not be found..."), you must also remove the following lines from every project file in the solution (apparently these used to be in the solution file in earlier versions of VS, but in VS2017 they are found in the project file for each project in the solution - e.g. [project].csproj):

SccProjectName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
SccAuxPath = "x"
SccLocalPath = "xxx"
SccProvider = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Thanks to the marked answer and other comments here for pointing this out:

visual source safe - how to remove bindings from solution w/o opening in visual studio

Combining this with Tabish's answer seems to be the most complete method of manually removing a solution from source control.

Upvotes: 24

meziantou
meziantou

Reputation: 21337

  • To remove the binding you can use Visual Studio : Menu File / Source Control / Advanced / Change Source Control.

  • You can also do it yourself by removing any SCC... from sln and csproj.

  • If you often export source files, you can use ExportSrc. It has many options such as remove TFS binding (ON by default).

Upvotes: 8

Richard Banks
Richard Banks

Reputation: 12546

If you want to permanently and completely detach the solution from source control, then try the following:

  1. Click the 'No' button to avoid connecting to TFS.
  2. In the file menu, go to the source control options and clear the bindings. You'll specifically want File - Source Control - Advanced - Change Source Control...
  3. Save the solution.

Next time you open the solution you won't be prompted to connect to TFS.

Upvotes: 60

Related Questions