Including the Microsoft Visual C++ runtime in your installer
search cancel

Including the Microsoft Visual C++ runtime in your installer

book

Article ID: 321489

calendar_today

Updated On: 05-09-2017

Products

VMware

Issue/Introduction

Symptoms:

Including the Microsoft Visual C++ runtime in your installer


Resolution

Note:In this example we use the Microsoft Visual C++ 2008 Redistributable Package (x86). Including a different version will be a similar process but you will need to check specific differences in the installation of the package.

Microsoft Visual C++ 2008 Redistributable Package (x86) is just an executable that can be bundled with the installer, deployed during the installation and run it in silent mode.

<componentList>
    <component>
        <name>vcruntime</name>
        <folderList>
            <folder>
                <name>vcfiles</name>
                <destination>${installdir}</destination>
                <distributionFileList>
                    <distributionFile>
                        <origin>vcredist_x86.exe</origin>
                    </distributionFile>
                </distributionFileList>
                <actionList>
                    <runProgram>
                        <progressText>Installing VC++ 8 runtime</progressText>
                        <program>${installdir}/vcredist_x86.exe</program>
                        <programArguments>/q:a /c:"msiexec /i vcredist.msi /qn /l*v ${system_temp_directory.dos}\vcredist_x86.log"</programArguments>
                    </runProgram>
                </actionList>
            </folder>
        </folderList>
    </component>
</componentList>

For installing the runtime package Windows Installer 3.1 or later is recommended. You can check that the user has the right version of msiexec and if not show a message to the user. You can include this checking in the <initializationActionList>

<initializationActionList>
    <setInstallerVariable name="msiexec" value="" />
    <setInstallerVariable name="msiexec" persist="1" value="msiexec.exe">
        <ruleList>
            <programTest name="msiexec.exe" condition="is_in_path" />
        </ruleList>
    </setInstallerVariable>
    <setInstallerVariable name="msiexec" persist="1" value="${windows_dir}/system32/msiexec.exe">
        <ruleList>
            <fileTest condition="exists" path="${windows_dir}/system32/msiexec.exe" />
            <compareText text="${msiexec}" value="" nocase="0" logic="equals" />
          </ruleList>
      </setInstallerVariable>
      <actionGroup>
          <actionList>
              <getWindowsFileVersionInfo type="version" path="${msiexec}" variable="msi_version" />
            <setInstallerVariableFromRegEx name="msi_version" text="${msi_version}" pattern="(^[0-9]+)\.([0-9]+)\..*" substitution="\1.\2" />
          </actionList>
          <ruleList>
              <compareText text="${msiexec}" value="" nocase="0" logic="does_not_equal" />
          </ruleList>
      </actionGroup>
      <throwError>
        <text>You need at least Windows Installer MSI version 3.1.</text>
        <ruleEvaluationLogic>or</ruleEvaluationLogic>
        <ruleList>
            <compareText text="${msiexec}" value="" nocase="0" logic="equals" />
            <compareValues value1="${msi_version}" value2="3.1" logic="less" />
          </ruleList>
      </throwError>
</initializationActionList>

Here you can find a demo xml project that will create an installer for the Microsoft Visual C++ 2008 Redistributable Package (x86). For building the demo installer you will need to place the vcredist_x86.exe executable and the attached xml file in the same folder.

Notice that this is only a demo project and you may need to add some uninstallation steps, some validations (for instance, check whether the user already has this runtime version installed) and integrate it with the installation of your own software.