Vs 2019 Compare Files

Lately I got questions asking for a quick lightweight tool to compare code files. Even though there are several tools like Beyond Compare, Araxis Merge, etc… which have lot of comparison and merging features, I use Visual Studio Code for quick file comparison during development or otherwise. For me, VS Code comes in handy as it is cross platform and I am using it on both macOS and Windows. I am using it for minor project development and even as a simple text editor. So naturally VS code is my go-to tool for file comparison. Here are the simple steps to compare the contents of two code files in VS Code.

Compare File Extension for VS2019

Control click any two files in Solution explorer and then right click and select “Compare Files…”. The configured third-party comparison tool will come up show a diff between the two files. Will also spawn a compare for subtype files if both files have subtype files, for example .

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 Studio2017EnterpriseCommon7IDE start "Compare files" /B /MIN "%vspath%devenv.exe" /diff %2 %1 First:%2 Second:%1 

    You might notice that I have reversed the %1 and %2 parameters 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.cmd to use it, and modify vspath if required to match the location of devenv.exe (depending on the Visual Studio version youre currently using, see footnote*) )
  • Either create a shortcut named “File Compare” for VS_FileCompare.cmd and 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. Thats 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.

    17 Answers 17 Sorted by:

    Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

    It falls back to sorting by highest score if no posts are trending. 932

    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 Reshetnikovs 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:

    Compare Files (2),  with Visual Studio Built-in Tool

    To display the Command window within Visual Studio, choose View => Other Windows => Command Window.

    can do the diff job, like this,

    It can also auto-complete paths to the files – making it easier to have the right, you type in the file name, the IntelliSense (auto-completion) will show all files with the name within Visual Studio solution, such like,

    It can also compare files that are not within Visual Studio by full file path, while different from the files within Solution, you have to type the full path of the file name, you will get IntelliSense from your path like this,

    FAQ

    How do I compare changes in Visual Studio 2019?

    Learn how to compare and merge source code in Visual Studio 2019.

    How to start comparing files:
    1. click File in the main menu bar, select the New sub-menu and then select Code Comparison;
    2. click Tools in the main menu bar, select the Code Compare sub-menu and then select New Code Comparison;

    How can I compare two js files in Visual Studio 2019?

    1. Open the Windows explorer via Win + E.
    2. Select two files to compare in the explorer.
    3. Drag and drop them as shown in the animation below:
    4. After a few seconds (depending on the launch time of Visual Studio), the results will be shown in Visual Studio:

    Does Visual Studio have a file compare tool?

    You can compare text files by using the default file-comparison tool integrated with Visual Studio, the Diff window.

    Can we compare two files in VS Code?

    Open VS Code with the files you are going to compare. Right-Click one file you want to compare => Select for Compare.