Visual Studio & diff Tools

Visual Studio & diff Tools

From above of crop anonymous African American female comparing data in papers at table of office

The difference between files

A diff tool (software to compare the difference between two text files) is a valuable asset to those of us who spend more than a healthy portion of the day looking at text files. Mostly this is to understand, what is different between the original and new version of some code.

Some time ago, I created a simple wrapper for Microsoft Visual Studio, to facilitate comparing files outside of an open project. But before looking into that, let’s look at some common alternative solutions.

Other Common Solutions

Most text editors have a plugin available (usually installable through a plugin manager) such as:

Visual Studio

For visual studio, there is the compare files functionality. But it’s a bit of a fiddle if you aren’t comparing files in an open project, or you aren’t using source control.

Documentation can be found here:

My Visual Studio Wrapper

As I do a lot of work using SSMS for prototyping and testing (a development phase where I’m not using source control), I needed an independent diff interface. I wanted to do a diff on files using Visual Studio, which isn’t so straightforward if the files aren’t already open with visual studio and using source control.

My solution was to manipulate the command line arguments to Visual Studio using python, including two file open dialogues which allow selecting files passed to the visual studio command line.

Usage

The easiest way to get “up and running” is to:

  1. Copy the .bat file somewhere accessible (such as the desktop)
  2. Change the python script reference in it to wherever the script is saved.
  3. Double click the .bat file whenever you need it, it will open a “file open” dialogue to select the first file to compare, then another for the second file. Once both files are selected it will open Visual Studio in diff mode.

Extending the “Send To” context menu

I run this with the bat file easily accessible.

My solution can be modified to be added to the “Send To” context menu in windows:

  1. In file explorer, go to the address: shell:sendto
  2. Add a .cmd file: Visual Studio Diff.cmd
  3. Put commands into it like a bash script (see below).
  4. Modify the python script to take an optional argument for the first file.

Visual Studio Diff.cmd

Populate the file with the below, changing the path reference:

@echo off
cls
python C:\Your\File\python_script.py %1

If you want to be able to manage multiple files, then you can modify the command file to something like:

@echo off
cls
:python_loop
IF "%1"=="" GOTO completed
python C:\Your\File\python_script.py %1
SHIFT
GOTO python_loop
:completed

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.