Click here to Skip to main content
Click here to Skip to main content

Managing Microsoft Team Foundation Version Control (TFVC) using "Team Foundation Sidekicks"

, 21 Jul 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A plug-in that allows you to "destroy" items from TFVC using the "Team Foundation Sidekicks" tool.

Overview

Team Foundation Version Control (TFVC) has the most common functionalities for version control systems (e.g.:. SourceSafe, Source Gear, CVS, Subversion, etc.) like management of file versions, management of users and permissions associated with the source code, or creating branches inside a project. TFVC also introduces new features such as "shelving and unshelving changes", "Check-in policies", and "exclusive or shared check out" (more info: MSDN).

Working with TFVC, you will be involved in many tasks such as: managing workspaces, setting user permissions, looking for who leaves files locked, comparing files history, destroying version control files/folders from TFS, etc. Some of these features are only available through command-line, and because of this, at the end of the day, you may write a lot command lines. This is where the "Team Foundation Sidekicks" tool comes into play.

Searching in the web for a graphical tool to handle most of these common tasks mentioned above, I found a site which describes one of its products as "a suite of tools for Microsoft Team Foundation Server administrators and advanced users, providing a Graphical User Interface for administrative and advanced version control tasks in multi-user TFS environments". And, the best part about it is that it is a freeware suite, and it may be used for commercial or noncommercial purposes under this license.

So, I created a test project inside TFS, and I started to evaluate all the product features, see more info here. After a playing with it for a while, I found a lot of cool functionalities, but the one that caught my attention was a menu item labeled "Add Sidekick..". And, I thought, maybe I can write my own TFS sidekick and plug it into this tool.

The problem

Sometimes, I need to permanently delete files/folders from TFVC (destroy files/folders) due to disk space requirements; I remove projects that might be created for testing purposes, etc. This feature is only available through the command-line interface. It depends on how deep the files/folders are inside the project structure. I may end up writing a long path to achieve my objective. So, it would be great to have a file explorer (similar to Windows Explorer for file systems) that would allow me to destroy files/folders I don't need. Let's try to create a user friendly interface for "destroying" files/folders from TFVC.

Building your own Team Foundation Sidekick

The first thing you need to do is to download and install the Team Foundation Sidekick tool (Team Explorer 2005 or 2008 must be installed on a computer in order to run the application, see implementation notes). Once you have installed Team Explorer and Team Foundation Sidekick, you'll have the API for extending the Team Foundation Version Control features. The Team Foundation Sidekicks controls must inherit from the BaseSidekickControl base class, and must also override the public Image property in order to create a menu and toolbar items for your sidekick entrance point, and initialize the public Name property to give a name to these items.

namespace MySidekick.Control
{
    public partial class DestroyFilesAndFoldersViewControl : BaseSidekickControl
    { 
        DestroyFilesAndFoldersController _controller = null;
        public DestroyFilesAndFoldersViewControl()
        {
            InitializeComponent();
            base.Name = "Destroy Sidekick";
        } 

        public override Image Image
        {
            get
            {
                return new Bitmap(@"c:\Test\Resources\Destroy.bmp");
            }
        }
    }
}

It is also recommended that we create a "Controller" class derived from TfsController in order to play safely with the connection and security contexts provided by the Team Foundation Sidekick application. In this class, we will write all the necessary methods to achieve our objectives.

namespace MySidekick.Controller
{
    public class DestroyFilesAndFoldersController : TfsController
    {
        public DestroyFilesAndFoldersController(TfsController 
               baseController) : base(baseController)
        {
        }
    }
}

Then, we need to override the Initialize method to create an instance of your controller class inside the DestroyFilesAndFoldersViewControlClass each time we load the control into the main form by clicking the menu or the toolbar items.

namespace MySidekick.Control
{
    public partial class DestroyFilesAndFoldersViewControl : 
                         BaseSidekickControl
    { 
        DestroyFilesAndFoldersController _controller = null;
        public DestroyFilesAndFoldersViewControl()
        {
            InitializeComponent();
            base.Name = "Destroy Sidekick";
        } 

        public override Image Image
        {
            get
            {
                return new Bitmap(@"c:\Test\Resources\Destroy.bmp");
            }
        }

        public override void Initialize(TfsController controller)
        {
            this._controller = new DestroyFilesAndFoldersController(controller);
        }
    }
}

At this point, we only have to write the method that actually destroys the files/folders from TFVC. If we explore the VersionControlServer class inside the Microsoft.TeamFoundation.VersionControl.Client assembly, we can see a method named Destroy.

public Item[] Destroy(ItemSpec itemSpec, VersionSpec versionSpec, 
       VersionSpec stopAt, DestroyFlags flags);

But, in the SDK Reference for Team Foundation Server, there is no information about the Destroy method. Also, we can try to get information about the parameters passed to the method like ItemSpec. All that we get is "This API supports the Team Foundation Server infrastructure and is not intended to be used directly from your code". All this lack of information makes sense because Destroy is a very dangerous operation; so, we need to remove all possible ambiguity about which items will be destroyed. (Of course, we need to have Administrator rights in the project). Maybe, it is a good practice to destroy only those files we previously deleted from the project.

public ItemSpec(string item, RecursionType recursionType, int deletionId);

Here, item is the full server path to the item or the folder to destroy (local file paths aren't allowed) and deletionId is assigned to the file/folder.

Once we can create an instance of the ItemSpec class:

public ItemSpec GetItemsSpec(string path, int deletionID)
{
   return new ItemSpec( path, RecursionType.Full, deletionID);
}

all we have to do is call the Destroy method using the base class and fulfill all its parameters.

public void Destroy(string path, int deletionID)
{
    base.VersionControl.Destroy(GetItemsSpec(path, deletionID), 
         VersionSpec.Latest, null, DestroyFlags.None);           
}

More information about the Destroy method is available here.

Then, we just need to compile the control to build the assembly that we will load into the Team Foundation Sidekick frame using the "Add Sidekick.." menu item.

Adding Sidekick

And, as you can see in the image below, we have a new menu item labeled "Destroy Sidekick".

Destroy ToolBarItem

Clicking on it, we will see the following screen. And now, we only have to search for the files/folders that we want to remove, and press Delete in the keyboard.

Deleting Files/Folders

That's all, I hope you enjoyed this article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Juan Manuel Elosegui
Software Developer
Spain Spain
Graduado de Ingenieria Mecánica en la Cujae (2001),
Universidad de la Habana, Cuba

Comments and Discussions

 
GeneralSmall fix proposed PinmemberJoseMarcenaro8-Apr-10 4:15 
GeneralRe: Small fix proposed PinmemberJuan Manuel Elosegui21-Apr-10 22:13 
GeneralExcellent PinmemberKev@Coastal14-Oct-08 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141030.1 | Last Updated 21 Jul 2012
Article Copyright 2008 by Juan Manuel Elosegui
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid