How to ignore white space when comparing source in Visual Studio / TFS?

Visual Studio-2010Tfs

Visual Studio-2010 Problem Overview


The compare tool in Visual Source Safe (pre TFS) had a handy checkbox to select "Ignore White Space".

Now we are using TFS with Visual Studio 2010, and the compare dialog no longer has this option. (A ridiculous oversight from Microsoft!)

So, is it possible somehow to work around this?

Visual Studio-2010 Solutions


Solution 1 - Visual Studio-2010

This is a workaround that seems to get around the problem.

In Visual Studio, select Tools / Options / Source Control / Visual Studio Team Foundation System and click the Configure User Tools button.

In the dialog, Add an item with the following settings.

  • Extension : .*
  • Operation : Compare
  • Command : C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
  • Arguments : %1 %2 %6 %7 %5 /ignorespace


Edit:
Depending on your Visual Studio version and instalation path (x64/x86), the command option may be...

VS2010: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
VS2012: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\diffmerge.exe
VS2013: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe
VS2015: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\vsDiffMerge.exe
VS2017: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe

In the argument option leave it with the same number of arguments as the VS suggests and just add /ignorespace in the end. For example, in the VS2015 it will be:

%1 %2 /ignorespace

Solution 2 - Visual Studio-2010

There is a "=" button on Visual Studio 2017 toolbar that helps to compare files as you want. Hope this screenshot will help.

Screenshot ofVisual Studio 2017 toolbar. The button with the equal sign is on the right, next to the lock icon. The tooltip for the button states

Solution 3 - Visual Studio-2010

The default diff tool in Visual Studio is extremely annoying. I suggest you use an alternative. WinMerge is my favourite. It also has an option to ignore whitespace (menu Edit -> Options -> Compare -> Ignore all (under the groupbox "Whitespace" at the top)).

See Using WinMerge with TFS.

Solution 4 - Visual Studio-2010

In VS2015 it's possible to "ignore white space" when comparing clicking a little icon with the = symbol.
Go to "View/Toolbars/Compare Files". In the toolbar click on "Ignore trim whitespace".

Update 2020: we struggled a lot solving conflicts with VS comparison tool and the Tortoise SVN one, so after a research we decided to install Devart Code Compare (free version) which has integration with VS2015/2017/2019, SVN (Tortoise and Ankh), TFS, Mercurial, GIT, etc. and Windows Explorer, so no more nightmares/confusion between different comparisons tools. Give it a try, it's extremely useful. It has also Merge to solve conflicts and Folder diff, which is really useful when SVN does not merge for some reason. Also, clicking on the left/right arrows to copy the changes is a feature that I really like.

Below VS image is from Devart website, but in my case I setup Code Compare to open it outside VS instead of embedded, I think it behaves better. And in VS Options > Source Control > Subversion Environment, I have this:

enter image description here

enter image description here

Solution 5 - Visual Studio-2010

in VS 2012, this might be what you're looking for with no changes to Diff tool.

Opening up the compare screen in VS 2012 and at the top you see the following option in the toolbar. as it might be the same comparison as user: Master screenshot.

enter image description here

Solution 6 - Visual Studio-2010

The default diff tool in VS 2013 does let you ignore whitespace after all. Just run the standard differencing process. When Visual Studio brings up the differences, look on the toolbar, where you will see an icon that looks like a document with 5 dots under it, as shown below. This button toggles whether the displayed differences ignore white space. This worked well enough for me; I wanted it to ignore changes in the white space caused by indentation. VS 2013 toolbar button for ignoring whitespace

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBillView Question on Stackoverflow
Solution 1 - Visual Studio-2010BillView Answer on Stackoverflow
Solution 2 - Visual Studio-2010MasterView Answer on Stackoverflow
Solution 3 - Visual Studio-2010e-mreView Answer on Stackoverflow
Solution 4 - Visual Studio-2010Luis HernandezView Answer on Stackoverflow
Solution 5 - Visual Studio-2010Michael EdmisonView Answer on Stackoverflow
Solution 6 - Visual Studio-2010Jim BlackView Answer on Stackoverflow