NSIS: How to ensure „VSTO Runtime“ is installed for .NET-projects

26.02.2016

You want to create a Windows Installer with NSIS for a VSTO .NET project?

Here you can find out how to handle with „VSTO Runtime“.

I needed to undertake many researches to find out how to handle with „VSTO Runtime“ by using NSIS to create an installer.
There were many articles about conditions where „VSTO Runtime“ must not be installed manually. E.g. if the user has installed Outlook 2010 with at least Service Pack 1. But I found out that in the case of that the Service Pack is installed manually and not by a Windows Update, installation of „VSTO Runtime“ is needed to execute your VSTO Add-In (see http://www.xltoolbox.net/blog/2015/01/net-vsto-add-ins-getting-prerequisites-right.html). This was the reason, because I undertook more researches about the topic with following conclusion:

You cannot rely on any Outlook version that your VSTO Add-In is working. The „VSTO Runtime“ must be a prerequisite and therefore has always to be installed if it’s not already.
For more information, see https://social.msdn.microsoft.com/Forums/vstudio/en-US/03737f48-981f-4e70-87f9-1970351c16d6/when-is-the-vstoruntime-needed-when-using-a-vstoaddin?forum=vsto

Therefore here is a tutorial how to ensure that „VSTO Runtime“ is installed:

With following command you can identify if VSTO Runtime is installed:

  ; The VSTO Runtime is installed if one of the following registry keys exist:
  ${registry::KeyExists} "HKLM\SOFTWARE\Microsoft\VSTO Runtime Setup\v4R" $R0;
  ${registry::KeyExists} "HKLM\SOFTWARE\Wow6432Node\Microsoft\VSTO Runtime Setup\v4R" $R1;

  ${IF} $R0 == "0"
    Goto Installed
  ${ENDIF}
  ${IF} $R1 == "0"
    Goto Installed
  ${ENDIF}

If the VSTO Runtime must be installed manually, it can be downloaded and installed using following commands:

!define DOWNLOAD_URL https://download.microsoft.com/download/7/A/F/7AFA5695-2B52-44AA-9A2D-FC431C231EDC/vstor_redist.exe
!define VstoRuntimeInstaller "$TEMP\VstoRuntimeSetup.exe"
NSISDL::download ${DOWNLOAD_URL} "${VstoRuntimeInstaller}"

Pop $0
${If} $0 == "cancel"
  goto SetupGoOnWithoutVstoRuntime
${ElseIf} $0 != "success"
  goto SetupGoOnWithoutVstoRuntime
${EndIf}

${StdUtils.ExecShellWaitEx} $0 $1 "${VstoRuntimeInstaller}" "open" ""
StrCmp $0 "error" ExecFailed
StrCmp $0 "no_wait" ExecFailed
StrCmp $0 "ok" WaitForProc
Abort

WaitForProc:
  ${StdUtils.WaitForProcEx} $2 $1
  StrCmp "$2" "" EndInstallVstoRuntime
  StrCmp "$2" "0" EndInstallVstoRuntime
  StrCmp "$2" "3010" EndInstallVstoRuntime
  StrCmp "$2" "8192" EndInstallVstoRuntime

If you have further questions, just add a comment.

Zurück zur Übersicht

Ein Kommentar zur “NSIS: How to ensure „VSTO Runtime“ is installed for .NET-projects

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*Pflichtfelder

*