Jun 19 2007

Using WinMerge with TFS

Category: .Net | ApplicationsRory Primrose @ 16:49

Someone at work was kind enough to figure out the correct command line switches to use in order to replace the standard TFS compare/merge tool with WinMerge. I originally blamed Pants for the info, but he then accused Eddie. Here are the goods:

In Visual Studio do the following:

  • Click on Tools menu
  • Click on Options menu item
  • Expand Source Control tree item
  • Select Visual Studio Team Foundation Server tree item
  • Click on Configure User Tools... button

Comparing

To use WinMerge as the Compare/Diff tool:

  • Click the Add... button
  • For Extension, type *
  • For Operation, select Compare
  • For Command, browse for C:\Program Files\WinMerge\WinMerge.exe
  • For Arguments, type /x /e /ub /wl /dl %6 /dr %7 %1 %2
  • Click OK to accept

Merging

To use WinMerge as the Merge tool:

  • Click the Add... button
  • For Extension, type *
  • For Operation, select Merge
  • For Command, browse for C:\Program Files\WinMerge\WinMerge.exe
  • For Arguments, type /x /e /ub /wl /dl %6 /dr %7 %1 %2 %4
  • Click OK to accept

Note: You need to click on the Save button on the tool bar within WinMerge merge to commit a merge before exiting the screen

Merge Error Workaround

If you encounter an error that says "The manual merge for <filename> has been canceled", the fix is to use a batch file to redirect the call to WinMerge to ensure a 0 return code.

This problem and workaround was originally found here by a colleague. He tested WinMerge and found that it does correctly return 0. Regardless of this, this batch workaround seems to work well. I have modified the original version to include my switches.

Create a batch file with the following content:

@rem winmergeFromTFS.bat
@rem 2007-08-01
@rem File created by Paul Oliver to get Winmerge to play nicely with TFS
@rem
@rem To use, tell TFS to use this command as the merge command
@rem And then set this as your arguments:
@rem  %6 %7 %1 %2 %4
"C:\Program Files\WinMerge\WinMerge.exe" /x /e /ub /wl /dl %1 /dr %2 %3 %4 %5
exit 0

The merge instructions above will then be changed to:

  • Click the Add... button
  • For Extension, type *
  • For Operation, select Merge
  • For Command, browse for C:\Program Files\WinMerge\winmergeFromTFS.bat
  • For Arguments, type %6 %7 %1 %2 %4
  • Click OK to accept

Modified C# Filter

WinMerge uses filter files to filter the entries found when comparing folders. The latest version of WinMerge bundles a C# filter file. I have updated it to include additional entries. Copy the content below into C:\Program Files\WinMerge\Filters\CSharp_loose.flt.

## This is a directory/file filter for WinMerge
## This filter suppresses various binaries found in Visual C# source trees
name: Visual C# loose
desc: Suppresses various binaries found in Visual C# source trees

## This is an inclusive (loose) filter
## (it lets through everything not specified)def: include
## Filters for filenames begin with f:
## Filters for directories begin with d:
## (Inline comments begin with " ##" and extend to the end of the line)
f: \.aps$ ## VC Binary version of resource file, for quick loading
f: \.bsc$ ## VC Browser database
f: \.dll$ ## Windows DLL
f: \.exe$ ## Windows executable
f: \.obj$ ## VC object module file
f: \.pdb$ ## VC program database file (debugging symbolic information)
f: \.res$ ## VC compiled resources file (output of RC [resource compiler])
f: \.suo$ ## VC options file (binary)
f: \.cache$ ## ??
f: \.resource$ ## Compiled resource file.
f: \.xfrm ## ??
f: \.bak$ ## backup
f: \.vssscc$ ## Source control metadata
f: \.vspscc$ ## Project source control metadata
f: \.user$ ## User settings
f: \.ReSharper$ ## ReSharper data

d: \\bin$ ## Build directory
d: \\obj$ ## Object directory
d: \\cvs$ ## CVS control directory
d: \\.svn$ ## Subversion control directory

Updated:

After checking out James Manning's blog post about compare/merge tools (thanks Grant), I have updated the command line arguments. For the most part, it is a merge of the switches in this original post and James' switches. The /x /e switches give the tool the same behaviour as the TFS tool for using the ESC key and identifying identical files. James' has include the use of the /ub /dl /dr switches to avoid MRU persistence and adds version labels to the left and right sides. I have also added /wl so that the left (server) side file is read-only.

If you want to know more about the WinMerge switches, you can get the online help from here.

Updated:

As suggested by Scott Munro, I have removed %3 from the merge switches, but I have still retained the /wl switch.

Updated:

Added TFS error workaround and my version of the C# filter.

Updated:

Added a reg file that contains the original settings outlined above (does not include workaround).

WinMerge for TFS.reg (1.12 kb)

Tags: , , ,

Comments

1.
Grant Grant says:

You must've missed James Manning's post:

blogs.msdn.com/jmanning/articles/535573.aspx

Smile

2.
Jeremy Jeremy says:

The suggested batch file did not work for me.  I had to change the last line from:
  exit 0
to:
  exit /B 0
which apparently is a Windows XP thing.

3.
David Barrett David Barrett says:

Thanks for the great reference post.  Just what I was looking for!

4.
Mark Mark says:

Thanks a ton!

5.
Colin White Colin White United States says:

Fantastic tip thank you very much.

6.
Jon Jon United States says:

I'm pretty sure that the batch file is no longer needed with the newest version of WinMerge.

7.
Rory Primrose Rory Primrose Australia says:

Hi Jon,

Yes, I think you are right. I haven't used the batch file workaround for a while. I only use it when I come across that particular problem.

8.
pingback zimnakawa.impaq.pl says:

Pingback from zimnakawa.impaq.pl

Tips [Visual Studio], TFS - Wykorzystanie WinMerge do porównywania - Programowanie z wyobraznia - Zimna Kawa

9.
Craig Lebowitz Craig Lebowitz United States says:

Thanks this was helpful

10.
pingback iratonline.net says:

Pingback from iratonline.net

iRatOnline » Using WinMerge with TFS

11.
Ken Ken United States says:

Is there a way to configure TFS to use WinMerge for FOLDER comparison?

12.
pingback kozlenko.info says:

Pingback from kozlenko.info

Maxim’s blog » links for 2009-06-25

13.
Rory Rory Australia says:

Sorry Ken, I missed your comment. I don't think folder compare is supported with TFS.

14.
Richard Dingwall Richard Dingwall United States says:

There's one feature I like about the built-in TFS diffmerge.exe - the "nagivate conflicts only" setting. Anyone know if any of these tools support that?

15.
Rory Primrose Rory Primrose Australia says:

I'm not familiar with that feature because I haven't used the TFS merge tool for so many years. Sounds like it just navigates to the next diff item in the file. I use keyboard shortcuts in Winmerge to navigate changes (Alt + up/down) and move changes left and right (Alt + left/right).

16.
Justicle Justicle Australia says:

Thanks for writing this up, the default diff was killing me.

17.
pingback codewrecks.com says:

Pingback from codewrecks.com

Merging and resolving conflicts

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading