Skip to content

Instantly share code, notes, and snippets.

@tormodfj
Last active September 13, 2018 12:02
Show Gist options
  • Save tormodfj/d47ac4f9c31faef14c90dd0f079fce08 to your computer and use it in GitHub Desktop.
Save tormodfj/d47ac4f9c31faef14c90dd0f079fce08 to your computer and use it in GitHub Desktop.

Using P4Merge with Visual Studio 2015/2017

The diff tool integrated with Visual Studio has been improving with every version. I still prefer dedicated diff/merge tools for the job, however, and P4Merge is my favorite. This small guide describes how to properly integrate P4Merge with Visual Studio 2015.

Note that this only applies when using TFS. If you use git, Visual Studio will use the diff/merge tools configured with git.

Installing P4Merge

The easiest method of installing P4Merge on your computer is with Chocolatey:

choco install -y p4merge

Wrapping the invocation

In order for Visual Studio 2015 to fully integrate with P4Merge, you need to wrap the invocation in two batch scripts:

p4diff.bat

@ECHO OFF
START /WAIT /D "C:\Program Files (x86)\Perforce\" p4merge.exe -dw -nl %6 -nr %7 %1 %2

p4merge.bat

@ECHO OFF
COPY /Y NUL %4
START /WAIT /D "C:\Program Files (x86)\Perforce\" p4merge.exe -dw -nb %8 -nl %6 -nr %7 -nm %9 %3 %1 %2 %4

Save these files somewhere safe, e.g. in the C:\Program Files (x86)\Perforce\ folder.

Configuring Visual Studio

In Visual Studio, go to OptionsSource ControlVisual Studio Team Foundation Server and click the Configure User Tools button. Then add these entries:

Compare

Setting Value
Extension .*
Operation Compare
Command C:\Program Files (x86)\Perforce\p4diff.bat (or where you saved the file)
Arguments %1 %2 "0" "0" "0" %6 %7

Merge

Setting Value
Extension .*
Operation Merge
Command C:\Program Files (x86)\Perforce\p4merge.bat (or where you saved the file)
Arguments %1 %2 %3 %4 "0" %6 %7 %8 %9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment