Including the Microsoft Visual C++ runtime in your installer

asked 14 Sep '11, 05:27

Jake's gravatar image

Jake ♦♦
826222226235
accept rate: 98%


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.

link

answered 14 Sep '11, 05:28

Jake's gravatar image

Jake ♦♦
826222226235
accept rate: 98%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×8
×4
×3
×1

Asked: 14 Sep '11, 05:27

Seen: 5,585 times

Last updated: 15 Sep '11, 07:54