Click here to Skip to main content
15,896,726 members
Articles / Programming Languages / C#
Article

TFS: Check Out - Get Latest

Rate me:
Please Sign up or sign in to vote.
3.78/5 (3 votes)
8 Sep 2007CPOL 63K   381   9   8
Addin for Visual Studio 2005 to prompt user to get the latest version before checking out a file for edit

Introduction

This project allows TFS users the ability to get the latest version before editing a file upon check-out. Based on the code started here, this project adds two things. One is the prompt - It asks the user if she/he wants to get the latest version (not always do they want to do this - They may be editing an earlier version on purpose). The second change is that the original requires the developer to modify the devenv.exe.config file to add the TFS server information. This project detects the currently connected server/project and uses that information.

Using the Code

The important changes come in the TFSAccess class. Notice below that the server is detected and when a change occurs, that is also detected.

C#
internal TFSAccess(DTE2 applicationObject)
{
  _TFSExt = applicationObject.GetObject
		("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") 
		as TeamFoundationServerExt;
  if (_TFSExt != null)
  {
    if (_TFSExt.ActiveProjectContext.ProjectName == null)
    {
      _TFSExt.ProjectContextChanged += 
		new EventHandler(this._TFSExt_ProjectContextChanged);
    }
    else
    {
      _previousDomainName = _TFSExt.ActiveProjectContext.DomainName;
      Connect();
    }
  }
}

private void _TFSExt_ProjectContextChanged(object sender, EventArgs e)
{
  if (_TFSExt != null && _TFSExt.ActiveProjectContext != null && 
			_TFSExt.ActiveProjectContext.DomainUri != null)
  {
    if (_previousDomainName != _TFSExt.ActiveProjectContext.DomainName)
    {
      Connect();
      this.OnConnectToTFS(new EventArgs());
    }
  }
  _previousDomainName = _TFSExt.ActiveProjectContext.DomainName;
}

History

  • 8th September, 2007: Initial post

License

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


Written By
Software Developer (Senior)
United States United States
Gabriel McAdams is a longtime .NET developer. He has specialized in ASP.NET and Web Services. Gabriel mostly develops using: C# ASP.NET Web Applications and Web Services SQL Server 2005/2008 - but over the course of over 10 years as a developer has used a lot of other technologies!

Comments and Discussions

 
GeneralCannot check-in file which were replaced to latest version by plugin Pin
TRVQ224-Jul-09 0:06
TRVQ224-Jul-09 0:06 
Hi,

I have VS 2005 and TFS 2005.

After applying plugin I have a problem that I cannot check-in a file which was replaced by plugin (after confirmation of replacing in dialog) and checked-out.

1) When I open a file for edit, VS shows this file as Read-only and when I try to save, VS asked to save as.. or overwrite file.
2) When I refresh list of files or pending changes, the status of file is changed from "lock, edit" to "lock"
3) When I try to check-in changes I've made, VS returns error message:
In case if step 2 is not executed:
Title: Microsoft Visual Studio<br />
Type: Error<br />
Message: Check-in Validation<br />
One or more of the selected pending changes not longer exist or has been modified by another process. Please refresh the list of pending changes and try again.

In case if step 2 is executed:
Title: Microsoft Visual Studio<br />
Type: Warning<br />
Message: No Changes to Check In<br />
All of the changes were either unmodified files or locks. The changes have been undone by the server.

I'm not sure but may be the problem is related to fact that we are working with SINGLE check-out on TFS (only one person can check-out file).

Thanks,
Ruslan
GeneralRe: Cannot check-in file which were replaced to latest version by plugin Pin
ghmcadams24-Jul-09 5:29
ghmcadams24-Jul-09 5:29 
GeneralRe: Cannot check-in file which were replaced to latest version by plugin Pin
TRVQ227-Jul-09 23:19
TRVQ227-Jul-09 23:19 
Questionerror? Pin
ColinBashBash9-Sep-08 11:28
ColinBashBash9-Sep-08 11:28 
AnswerRe: error? Pin
ghmcadams10-Sep-08 8:18
ghmcadams10-Sep-08 8:18 
GeneralRe: error? Pin
ColinBashBash29-Sep-08 10:39
ColinBashBash29-Sep-08 10:39 
GeneralUnable to Connect TFS Pin
Thulasi Rao26-May-08 19:44
Thulasi Rao26-May-08 19:44 
GeneralRe: Unable to Connect TFS Pin
ghmcadams10-Sep-08 8:20
ghmcadams10-Sep-08 8:20 

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

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