Compare Two Files in Visual Studio
I Saw the New Comparison Tool in Visual Studio 2012 for Comparing Two Files or Two Versions of a File. I Like It. but When I Tried to Find It I Couldn't It...
I saw the new comparison tool in Visual Studio 2012 for comparing two files or two versions of a file. I like it. But when I tried to find it I couldn't it, because I don't use TFS.
Is there a way how I can just compare two files with the built-in feature in Visual Studio (but without TFS)?
17 Answers
You can invoke devenv.exe /diff list1.txt list2.txt from the Visual Studio Developer Command Prompt or, if a Visual Studio instance is already running, you can type Tools.DiffFiles in the Command window, with a handy file name completion:
Inspired by Vladimir Reshetnikov's answer above, I found a very comfortable way how you can instantly compare two files with Visual Studio by using drag and drop or via the "Send To" context menu. It only requires a little preparation which you need to do once and then it is useful like a Swiss army knife.
Visual Studio already has everything you need, and there are only some configuration steps required to make this working:
File compare using drag & drop
Preparation:
Create a new batch file using your favorite text editor. Type the following:
@echo off setlocal set vspath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE start "Compare files" /B /MIN "%vspath%\devenv.exe" /diff %2 %1 First:'%2' Second:'%1'You might notice that I have reversed the
%1and%2parameters in the batch. This is because I noticed that the file explorer passes the second file as the first parameter, and then the first file as the second parameter.Save this code as
VS_FileCompare.cmdto use it, and modifyvspathif required to match the location ofdevenv.exe(depending on the Visual Studio version you're currently using, see footnote*) )Either create a shortcut named "File Compare" for
VS_FileCompare.cmdand place it on the desktop (as used in the animation below), so it is always available to drag & drop files onto it or directly place the batch file on the desktop. That's all!
Usage:
Open the Windows explorer via Win + E
Select two files to compare in the explorer
Drag and drop them as shown in the animation below:
After a few seconds (depending on the launch time of Visual Studio), the results will be shown in Visual Studio:
Note: It does not harm if Visual Studio is already open. In this case it will just open up a new window within the running instance of Visual Studio. So you can compare multiple file pairs, but please ensure you have selected only two files at a time.