14

I have two VS C# projects (specifically, for an Outlook plugin) that I believe to be very similar with the exception of perhaps 100 lines of code. I'm slightly worried that there might be other configuration options for the project that are different, so I'd like to compare those two.

What is the best way to see the differences between the two codebases?

I've tried putting the two projects in parallel directories and using diff, but since the projects are named differently, some of the files don't match up. I'm just wondering if there's an easier way to do this?

Peyton
  • 441
  • 1
  • 3
  • 14
  • Do the the classes in 'different' source files have same names? You could try to build both projects and compare the built Assemblies: http://stackoverflow.com/questions/652432/compare-compiled-net-assemblies – rudolf_franek Oct 26 '11 at 19:05

4 Answers4

16

It sounds like you need something like WinMerge to go through and point out the differences between the two projects. It's free, and I know you can compare folder contents with WinMerge, so that's probably a good place to start. Run WinMerge on the project folders and it should generate a detailed comparison outlining the differences between the files.

See this tutorial on comparing folders:
http://manual.winmerge.org/CompareDirs.html

enter image description here

James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • I'm pretty sure there are ways of accounting for that. At worst case, I know you can select specific files to compare. – James Johnson Oct 26 '11 at 19:18
  • 1
    Dealing with renamed files is difficult. If the files have been both renamed and edited slightly, it would be difficult for a comparison tool to know that they were actually the same file at some point. If it tried to do this, it would probably give you a lot of false positives where it would see similar files of different names. And there would have to be some threshold that it used to decide if two similar files were similar/different enough to make that decision. – AaronLS Oct 26 '11 at 19:27
  • In such cases, you could always select the files to compare manually. I know that's not ideal, but it should work assuming that there are only a few renamed files. – James Johnson Oct 26 '11 at 19:35
  • I used the WinMerge tool with additional suggestions from the other answer about un-renaming renamed files. Thanks to all for the great ideas! – Peyton Nov 29 '11 at 16:24
  • this saved my day – Robin33 Aug 09 '21 at 12:17
7

I strongly recommend Code Compare (not affiliated, just a happy user) for this kind of job - there is a free version and a more advanced commercial version.

It integrates nicely with VS and has syntax highlighting for C#, C/C++ etc.

Yahia
  • 69,653
  • 9
  • 115
  • 144
2

One way: Make copies of both projects, rename the files and folders in one to match the files and folders in the other, then use your favorite folder compare tool to compare the two.

This won't help you unless there was a true copy-and-paste relationship between the two projects.

The better way would be to use refactoring. After creating unit tests for both projects and achieving an adequate level of code coverage, go class by class and method by method using refactoring to try to make pairs of methods identical. You may then identify methods that should be pulled into base classes or moved into other classes.

Eventually, you may find pairs of classes which are identical. Move those classes into a common library, then rename all uses of one of the classes to be a use of the other. Then delete the one no longer used.

Repeat until there is no more duplication.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
1

If you've got modifications like renames or partial code moves, importing both versions into a single git repository (as two different commits of a single directory) could help. Git tracks contents of files, not the files themselves, so it is possible to find out e.g. a function that has been moved from one file to another.

liori
  • 40,917
  • 13
  • 78
  • 105