Comparing files in Visual Studio

Mads Kristensen

As developers, we often need to compare two files to find the differences. Sometimes, even comparing the content of the clipboard with a file on disk. And again, sometimes comparing our local changes to previous versions from our Git commit history. There is no straightforward way in Visual Studio to do those things today, but in this month’s experiment we’re going to change that.

Image diff view

Various editors and IDEs offer this feature today, but Visual Studio has required the use of extensions such as VS Diff to provide the feature. An interesting thing about the various implementations is that they offer slightly different features and with different UI paradigms. They all perform basic comparison between files rather well, and we think it’s time we figured out how to design this feature for Visual Studio.

A feature request on the Visual Studio Developer Community is also now gaining steam asking for file comparison, so please vote and comment if you agree.

So, with increased interest and multiple viable solutions, what would the right implementation look like for Visual Studio users?

Let’s do an experiment to find out.

The experiment

We’re starting out with an extension to kick off the experiment. We call it File Differ and the first iteration adds basic file diffing capabilities.

Solution Explorer

Here’s are the commands available from the right-click menu in Solution Explorer:

  • Compare two files in Solution Explorer
  • Compare file with another file on disks
  • Compare file with content of clipboard
  • Compare file with its unmodified version

Compare selected files

Select two files in Solution Explorer and right-click to bring up the context menu.

Image multi selection

Then select Selected Files to see them side-by-side in the diff view.

Compare with a file on disk

If you only selected a single file, a file selector prompt will show up to let you select which file on disk to diff against.

Image single selection

Compare with clipboard

If there is text content on the clipboard, you can compare a file with it by selecting File with Clipboard from the context menu.

Code editor

There are also commands specific to the code editor. By right-clicking inside the code editor, you’ll get the following options for diffing:

  • Compare selection with clipboard
  • Compare active file with clipboard
  • Compare active file with saved version
  • Compare active file with file on disk

Image editor

Next steps

If this feature is interesting to you, please install the File Differ extension and take it for a ride. Make sure to share any ideas and bugs on the GitHub issue tracker, and feel free to send pull requests too. The feature request ticket is a suitable place to share your comments and thoughts, so make sure to vote and comment there as well.

Do you like the idea of community experiments like this one? Let us know in the comments below.


Discussion is closed. Login to edit/delete existing comments.

  • Artem Grunin 1

    What happened with old good View -> Other Windows -> Command Window (Ctrl+W,A for my preset) and then type

    >Tools.DiffFiles "file.a" "file.b"


    Comparing with clipboard is not available, but I can’t remember if I ever have such need

    • Mads KristensenMicrosoft employee 2

      That command is still there and is also what is being used for some of the features in the experimental extension

      • Artem Grunin 3

        Thank you, Mads. If you don’t mind, I can suggest much more needed diff tool a bit similar to Beyond Compare suggested in comments bellow. In short I want to have “pull” experience to be similar to current “push” to be aware of changes made by other authors. I believe it’ll help to detect much more issues than PR review can.

        I used to be Java developer in the beginning of my career. We used Eclipse IDE, probably with several plugins there, and since that time I miss it’s killer feature for getting remote changes locally. Basically it shows a list of changed files (including new and deleted files, as well as authors of this changes) and allows you compare (and even cherry pick) changes before you take each one. Additionally it was able to merge conflicts if any. Yes, I can fetch and then check details of each commit but this experience sucks as it doesn’t force code review on each pull.

  • Mason Boswell 1

    I would love to see WinDiff.exe brought back and maintained, dark theme added. I still use it every day and have for 20+ years.

    • David Pilcher 0

      For basic compares, I still use WinDiff too. For multi-folder find a set of files that are different, WinMerge.

      File differencing/comparison is a key part of developer workflow. Having tools come with VS and perhaps standalone in the Store will be useful.

  • Eric Harmon 6

    At some point, I’d like to see Folder Comparison as well. I’ve used BeyondCompare for many, many years (not every day or anything, but when I need to compare files or folders, that’s my goto tool). If I could get usable file and folder comparison baked into Visual Studio, I think I’d be able to drop Beyond Compare in favor of VS.

  • David Lowndes 0

    Seems like a great addition. I’d like it even more if it could invoke a 3rd party diff tool such as Beyond Compare – can it … please?

  • Matthew Jimenez 0

    A welcome addition! File compare in Visual Studio has improved over the last few versions to a point that I rarely use an external tool.
    One thing I still would like is to NEVER prevent text editing from within the compare tool. I’m not sure why certain file types (mainly csproj files) prevent this.

    • Oleg TkachenkoMicrosoft employee 0

      This limitation is mostly removed in 17.4. There are still limitations on editing left file, we are working on it.

  • James M Curran 3

    A feature I’d really like: The ability to compare two sections of the same file (greatly needed for refactoring code)

    • Mads KristensenMicrosoft employee 4

      That’s included. You can compare the text selection with what’s on the clipboard

    • Michel Bretschneider 0

      You should look have look SematicMerge (or gmaster if you can find it anywhere) which detects changes like moving a method within a file.

  • c h 0

    VS2019 and 2022. How to install for 2019?

    • Mads KristensenMicrosoft employee 0

      This is available for VS 2022 only

  • V D 1

    Is there a Diff API available to plugins?
    It would be great to use 3rd party diff tools directly in the VS editor and not in a separate window.

    • Mads KristensenMicrosoft employee 0

      The only API available is a command (`Tools.DiffFiles `) your extension can call. That’s what this extension uses too

    • anonymous 0

      this comment has been deleted.

  • Bill Casey 1

    This is a tangential, slightly off-topic comment about ‘differences’. I am still really bent out of shape about the change of timestamp when loading a branch from GIT. This creates a DIFFERENCE from when I made the commit, which IMHO should PRESERVE not only code changes but WHEN they were made thus creating ZERO differences! Loading historical snapshots of a project’s state at a certain time should include a file’s timestamp AT THAT TIME! {Sorry for all the caps but this is the #1 thing that bothers me about Visual Studio.} I know this isn’t about differences in file content but that’s just tough – placing the current timestamp on retrieved GIT project file snapshots is not nice (boy, did I clean THAT up!).

    • Ira Hsu 0

      Highly agree with this comment! Several times I have loaded code from Git, and then when it comes time to promote up to our test tier, it looks like I need to upload all the files, since they have a newer date than what is on the test server. It’s hard to tell what files have been actually worked on without restoring their actual time/date stamp. Please make this happen!

  • James Foye 0

    Well I gave up again on migrating to VS 2022, as I could not even save changes to a file. But hey, this looks like a great feature.

    • Oleg TkachenkoMicrosoft employee 0

      Please report it via Help/Send Feedback/Report a Problem and post feedback ticket link, this is not a known issue.

  • Adin Aronson 1

    Thanks Mad.

    Let me tell you which Compare option is REALLY missing.
    There is no way to compare a currently modified file with a previous version in GIT. You can only compare your file to the “unmodified version” of the file.

    At least with this extension I can open a previous version, Select All, and copy to clipboard and then go back to my currently modified version and “compare to clipboard”

    • Mads KristensenMicrosoft employee 1

      The team is planning to provide this feature in a future update. I agree, it is really missing, but I’m glad you’re able to use the workaround in the extension to unblock you for the time being.

      • Michael Bond 2

        Rather than just the previous version if you can extend it to any GIT branches so that I can compare the current version to one from a different branch and see the differences.

  • Steven Quick 1

    As others have mentioned beyond compare is the gold standard imo, 3 way merge view with a 4th pane for output that you can modify.

    Anyone doing a git merge or rebase without a proper 3 way merge tool is playing with one arm tied behind their back.

    • Michel Bretschneider 0

      If beyond compare is the gold standard, SemanticMerge has to be platin, right?

  • Michel Bretschneider 1

    Nice, so in simple cases I don’t have to leave VS for that.

    Have you considered semantic diffing like the gmaster git client had? Currently SemanticMerge which is shipped with Unity’s Plastic SCM seems to be the only tool on the market that has this capability.

  • CAK Cy 0

    I’ll comment on something that may seem unrelated to the article but it is to me. Many times we have added extensions developed by Microsoft, worked with them (took them for a ride) loved them and then Microsoft (for one reason or another) instead of making the extension part of the main Visual Studio software, it ditched them, leaving us developers wondering and complaining about Microsoft’s decision. I will mention for example the “Custom Document Well” (CDW) that many of us, developers found to be an extremely helpful extension. For whatever reason, instead of improving it or even rewriting it to abide to the new standards, Microsoft decided to re-invent the wheel and started designing the Document Well from scratch which is still ages behind CDW.

    So, with all due respect, no Mads. Despite all the good intentions and potential of the new extension I choose not to take it for a ride, only to wake up one day and be told by Microsoft “Sorry, this no longer exists because A or B”

    • Chuck Ryan 0

      I strongly agree with this. Over the last decade having the rug pulled out from under us by Microsoft has become the norm over all their products.

      I used to be a skeptic of open-source projects, as there always existed the risk of a project being abandoned, but now those projects have a better record of longevity and responsive support than Microsoft. What puts the open-source projects over the top for me is the ability to download the project source and ensure that we have the ability to modify and build the project in the event it is abandoned, something we know Microsoft will outright refuse to consider in most cases.

      These days I try to ignore most of the new Visual Studio enhancements, beyond the core development features, as I do not feel I can rely on them being supported long term.

  • miliu99 0

    As we are moving to the web, the feature I miss the most in VS is JSON diff or YAML diff. Is there a plan to add those diff formats?

Feedback usabilla icon