Including the Microsoft Visual C++ runtime in your installer
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.