Get latest version on checkout with VS 2008 and TFS 2005

   —   
Here are some tips how to make the Get latest version on Checkout feature work with Team Foundation Server, particulary in combination of VS 2008 and TFS 2005.
Hi there!

Those of you who have TFS 2005 and VS 2005 probably already know that there is an add-in which does the get latest version for you. You can find it here:

http://blogs.microsoft.co.il/blogs/srlteam/archive/2007/03/24/TFS-GetLatest-version-on-check_2D00_out-Add_2D00_In.aspx

Unfortunately, such add-in cannot be found for VS 2008. And the Visual Studio 2008 does not support this feature with Team Foundation Server 2005, only with TFS 2008 which is bad if you have the combination of VS 2005 and TFS 2008.

I wrote a simple macro which can help you to deal with this inconvenience when you are using VS 2008 with TFS 2005. Perform following steps to use it:

1) Open your solution in VS 2008
2) Open the menu Tools -> Macros -> Macro Explorer
3) On the right, open (doubleclick) the Module1, the macro editor opens (you may get the error that something is missing, just ignore it)
4) In the tree on the left, open EnvironmentEvents and enter the following code:

Import System.IO

...

Public Sub GetLatest(ByVal DocumentPath As String)
  Dim attr As FileAttributes
  attr = File.GetAttributes(DocumentPath)

  If (attr And FileAttributes.ReadOnly) Then
    DTE.ExecuteCommand("File.TfsGetLatestVersion")
  End If
End Sub

Public Sub TextDocumentKeyPressEvents_BeforeKeyPress(ByVal KeyPress As String, ByVal Selection As EnvDTE.TextSelection, ByVal InStatementCompletion, As Boolean, ByRef CancelKeyPress As Boolean) Handles TextDocumentKeyPressEvents.BeforeKeyPress
  Dim doc As Document = DTE.ActiveDocument
  If Not doc Is Nothing Then
    GetLatest(doc.Path & doc.Name)
  End If
End Sub


The macro simply attempts to get the latest version if the key is stroked and the file appears to be checked-in (is read only), that is all, no magic in it.

Now close the macro editor and when you open some checked-in document and try to edit it with a key stroke (the usual way how you start to edit the document), its latest version automatically loads from the server.

The macro isn't perfect but covers a lot of situations where you need to get the latest version automatically.

If you know about any better solution, please let me know. (Except for upgrading to TFS 2008, that is currently not an option for us) ...
Share this article on   LinkedIn

Martin Hejtmanek

Hi, I am the CTO of Kentico and I will be constantly providing you the information about current development process and other interesting technical things you might want to know about Kentico.

Comments

Brynell commented on

Hey, that post leaves me feeling foolsih. Kudos to you!