Comparing files using Visual Studio

The diff tool of Visual Studio is very good to compare 2 files. You can use it to compare two versions of the same file directly in Visual Studio. But you can also use it to compare 2 files that are not in a solution.

Using the command line

  1. Open the developer command prompt from the start menu, so devenv.exe is already in the path
  2. Use the following command line:
devenv /diff file1.cs file2.cs

Using the Command Window in Visual Studio

If you have already opened Visual Studio, you can use the Command Window to diff files.

  1. Open the Command Window using the Quick Launch or using the keyboard Ctrl+W, A

  1. Using the command Tools.DiffFiles with the 2 files to compare:
Tools.DiffFiles "file1.cs"  "file2.cs"

You'll get the same result as with the command line: