A day with .Net

My day to day experince in .net

Remove TFS binding – The solution you are opening bound to source control

Posted by vivekcek on November 23, 2012

I was planning to move my project from TFS to SVN. So first i check out my code from TFS and copy the solution folder to some other place. But unfortunately when i open my solution a warning message like, ‘The solution you are opening bound to source control’.

I hate this massage. My code is check out from TFS still this message. I want to remove so tried the below code. Create a console application with this code.

using System;
using System.IO;

namespace Unbind
{
  class Program
  {
    static void RemoveBindings(string[] files,StreamWriter Log)
    {
      foreach (string file in files)
      {
        try
        {
          Log.WriteLine(file);
          string line;
          bool startDeleting = false;
          StreamReader SR = new StreamReader(file);
          StreamWriter SW = new StreamWriter(file + ".new.txt", false);
          while ((line = SR.ReadLine()) != null)
          {
            if (line.ToLower().Contains("globalsection(teamfoundationversioncontrol)"))
            {
              startDeleting = true;
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else if (startDeleting && line.ToLower().Contains("endglobalsection"))
            {
              startDeleting = false;
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else if (startDeleting)
            {
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else if (line.ToLower().Contains("\tscc") || line.ToLower().Contains("<scc"))
            {
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else
            {
              SW.WriteLine(line);
            }
          }
          SR.Close();
          SW.Close();
          File.Copy(file + ".new.txt", file, true);
          File.Delete(file + ".new.txt");
        }
        catch (Exception)
        {
        }
      }
    }

    static void Main(string[] args)
    {
      Console.WriteLine("Have you made a backup first? Y=continue");
      string prompt = Console.ReadLine();
      if (prompt.ToLower() != "y")
      {
        return;
      }

      // Looks in current directory and below for *.sln and *.proj files
      // For testing, I set the Project's startup folder properties to C:\FF\FabrikamFiber

      StreamWriter Log = new StreamWriter("log.txt", false);
      RemoveBindings(Directory.GetFiles(".", "*.sln", SearchOption.AllDirectories),Log);
      RemoveBindings(Directory.GetFiles(".", "*.*proj",SearchOption.AllDirectories),Log);
      Log.Close();
    }
  }
}

In the project properties set your working directory as the directory hold your solution. This solution find all .sln and .proj files inside that folder and remove TFS binding.

Use thi App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s