Depending on Windows and Office version, there are various different scenarios of the prerequisites that need to be met in order to install and run a VSTO add-in.
In theory, Microsoft has all the information that is needed to understand the prerequisites on their website. In practice, it turned out (for me) that it was quite difficult to get it right for all combinations.
Here’s my synopsis of the different installation scenarios and how to recognize and handle them.
.NET 4.0 runtime
The .NET 4.0 runtime is not included in any version of Windows by default: Windows 7 comes with .NET 3.5, and Windows 8 has .NET 4.5 included. .NET 4.5 can also be used with projects targeting 4.0 (I tried it), and it creates the same registry keys as the ones listed below. On the other hand, .NET 3.5 of course is not enough for projects targeting 4.0. Therefore, it has to be installed separately (chances are that some other application has the .NET 4.0 requirement as well and has previously taken care of installing it).
The .NET runtime bitness must be the same as the Windows bitness. Luckily, there is only one installer for both 32-bit and 64-bit Windows, making things somewhat easier.
To find out if the .NET 4.0 runtime (or 4.5, see above) is installed, check the registry:
HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4on 32-bit Windows
HKLM\SOFTWARE\Wow6432NodeMicrosoft\NET Framework Setup\NDP\v4on 64-bit Windows
VSTO runtime for .NET 4.0
The VSTO runtime is a little more difficult to deal with than the .NET runtime, because its bitness must match the bitness of the installed Office, its installed bitness cannot be determined by examining the registry (not that I am aware of anyway), and because some versions of Office come bundled with the VSTO runtime.
Generally speaking, the presence of a VSTO runtime can be established by checking if one of these registry keys is present:
HKLM\SOFTWARE\Microsoft\VSTO Runtime Setup\v4R
HKLM\SOFTWARE\Microsoft\VSTO Runtime Setup\v4M
HKLM\SOFTWARE\Wow6432Node\Microsoft\VSTO Runtime Setup\v4R
HKLM\SOFTWARE\Wow6432Node\Microsoft\VSTO Runtime Setup\v4M
The first two keys are found on 32-bit Windows and the latter two on 64-bit Windows (see related Q&A on StackOverflow).
The bitness of the VSTO runtime must be the same as the Office bitness.
Similar to the .NET runtime, there is only one VSTO runtime
installer that takes care of both 32-bit and 64-bit setups.
However, as far as I know, you cannot tell from the registry keys if the
32-bit or the 64-bit variant (or both) of the VSTO runtime is installed.
The presence or absence of the
Wow6432Node crumb in the above registry
keys depends only on the bitness of Windows, not the VSTO runtime.
In my experience, the keys ending with
v4M are unreliable indicators
that a VSTO add-in can be loaded by Office. I had to install the
vstor_redist.exe, which made the
v4R keys appear, and then
the add-in would load.
To find out what version and possibly service pack of Office is installed, examine
[VER] is the Office version number (12.0 for Office 2007, 14.0 for
Office 2010, 15.0 for Office 2013). The
Wow6432Node part is required on
64-bit Windows, regardless of the bitness of Office. (See below for
finding out the bitness of Office.)
This registry value contains the version and build number of the originally installed Office. Note that the version and build that is displayed in the ‘Help’ panel of the Office button (or ‘backstage view’). This latter version and build number reflect any hotfix packages that are installed on top of the originally installed version.
ProductVersion key is removed when Office is uninstalled.
To determine if Excel was actually installed with a given Office version,
test the presence of
The Office bitness can be examined in the string value
which has the value
x86 and exists only if a 32-bit Office is
installed on a 64-bit Windows (note the absence of the
part!). The value does not exist if 64-bit Office is installed on 64-bit
Windows. It might be confusing that the value resides in the
key, but that is the way it is, even if only Excel is installed from the
package and nothing else.
There is only a 32-bit edition of Office 2007, and it does not come bundled with the VSTO runtime. Thus, both the .NET runtime and the VSTO runtime need to be installed separately if they have not been installed previously, which can be asserted by testing the presence of the registry keys mentioned above.
Office 2010 without service pack
Office 2010 (version 14, build 6029) was the first version that came in both 32-bit and 64-bit flavors, and it did not bundle the VSTO runtime for .NET 4.0.
The situation is the same as with Office 2007.
Office 2010 Service Pack 1 and newer
Office 2010 SP1 and Office 2013 bundle the VSTO runtime for .NET 4.0, and this has a huge impact on the installation requirements of an add-in. If .NET 4.0 is not installed, a VSTO add-in will not be loaded by Office (and no error message will be shown, but see this solution). However, as soon as the .NET 4.0 runtime is installed and an office application (such as Excel) is started, the VSTO runtime will automagically be configured, and the add-in will load. This works without problems on my test system.
To conclude, my algorithm to detect which prerequisites need to be downloaded and installed during installation of an Office add-in is as follows:
HKLM\SOFTWARE\[Wow6432Node\]Microsoft\NET Framework Setup\NDP\v4
is present and install the .NET runtime if it isn’t.
Find out the installed Office version(s) by testing
[VER]. (In fact, start with a version number higher than 15.0 to include future versions as well.) Microsoft discourages installing concurrent versions of Office on a single system, but I expect that some users do have two Office versions on one PC.
If Office 2007 (version 12) or Office 2010 without service pack (version 14, build 4763) is installed: check if
HKLM\SOFTWARE\Microsoft\VSTO Runtime Setup\v4R
is present and install the VSTO runtime if it isn’t.
If Office 2010 Service Pack 1 (version 14, build 6029) or any newer Office version is installed, Office will take care of configuring the VSTO runtime.
I still don’t know if a VSTO runtime that is bundled with a more recent
Office can also be used by Office 2007 or Office 2010 without service
pack, but I guess the safest method is to download and install the runtime
if 2007/2010 are detected and the
v4R registry key is not presend,
regardless of any concurrent installation of Office 2010 SP1 or newer.
Note added 2016-03-31: I have written a generic installer for VSTO add-ins that I use for two of my projects:
https://github.com/bovender/VstoAddinInstaller – you may want to have a look at it.