Skip to content

Instantly share code, notes, and snippets.

@throwaway96
Created March 26, 2024 01:13
Show Gist options
  • Save throwaway96/5a8976eed1aaf7ccbb2dc39ddb436382 to your computer and use it in GitHub Desktop.
Save throwaway96/5a8976eed1aaf7ccbb2dc39ddb436382 to your computer and use it in GitHub Desktop.
WinMerge "Visual Studio not installed" error with "Disassemble IL Code" and "Disassemble Native Code"

Introduction

WinMerge's Compare As > Disassemble IL Code and Disassemble Native Code options appear to be almost completely undocumented, so when I came across the error message Visual Studio not installed I wasn't able to find any relevant information online. I'm hoping this document will help anyone who runs into the same problem in the future.

If you don't care about the explanation, you should be able to solve the problem by opening the Visual Studio "Developer Command Prompt" and running this:

mkdir "%APPDATA%\WinMerge\Commands\ildasm" "%APPDATA%\WinMerge\Commands\dumpbin"
where.exe ildasm.exe >"%APPDATA%\WinMerge\Commands\ildasm\ildasm.txt"
where.exe dumpbin.exe >"%APPDATA%\WinMerge\Commands\dumpbin\dumpbinpath.txt"

The Error

When I tried using Disassemble Native Code to compare a pair of DLLs I knew were different, WinMerge told me they were identical. It turned out the comparison was between two copies of the same error message: Visual Studio not installed.

However, I did have Visual Studio installed, so I was curious about how this WinMerge plugin came to that conclusion. Looking in ${WINMERGE_HOME}\MergePlugins\Plugins.xml (WINMERGE_HOME refers to the installation path of WinMerge, e.g. C:\Program Files\WinMerge), I could see that the IL and native options called ${WINMERGE_HOME}\Commands\ildasm\ildasm.bat and ${WINMERGE_HOME}\Commands\dumpbin\dumpbin.bat, respectively. Both of those scripts rely on %programfiles(x86)%\microsoft visual studio\installer\vswhere.exe to find Visual Studio installations, and since version 2.0 vswhere won't find preview VS installations by default.

The Solution

Once these scripts find the executable they're looking for, they cache its path. So I was able to just put the full path of each file into %APPDATA%\WinMerge\Commands\dumpbin\dumpbinpath.txt and %APPDATA%\WinMerge\Commands\ildasm\ildasmpath.txt. (I had to create all these directories as %APPDATA%\WinMerge didn't already exist.)

For me, the paths were:

C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.40.33617\bin\Hostx64\x64\dumpbin.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8.1 Tools\ildasm.exe

Yours will likely be different since they depend on MSVC/.NET SDK versions. You can find the paths yourself the same way the batch scripts do: launch the "Developer Command Prompt"/"Developer PowerShell" for VS and run where.exe ildasm.exe/where.exe dumpbin.exe.

More Details

Neither script uses the path returned by vswhere to directly locate the target executable. Instead, they both use vsdevcmd.bat to populate PATH with the directories containing the targets. Then they use the where command, piping its output to the .txt files previously mentioned.

There is also a vswhere feature that may be useful in similar cases, although you'd have to pick out the correct host/target platforms:

vswhere -prerelease -find **\dumpbin.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment