Wixsharp: Best way to run vcredist in Wix# with embedded UI

Created on 3 Apr 2018  路  4Comments  路  Source: oleg-shilo/wixsharp

Dear Oleg
I developed an installer based on the Embedded_UI example.
Everything runs well but now I need to integrate the vcredist installation into mine.
I tried to add a custom action on AfterInstall event of the ManagedProject class to run manually the vcredist.exe package which is part of my installation. But I got the error from vcredist package that another installation is in progress.
Which is the best way to integrate the vcredist installation into a Wix# project?
Thanks

question

All 4 comments

You cannot do that. MSI atomic/transnational model specifically prohibits that. From the moment the installation started (you click "Install" button) and until the last the last Custom Action is executed no other installation can be active. MSI runtime just prevents any other installs.

Where does it leave you? You can use Bootstrapper (WiX Burn). It is designed to pack and chaim multiple installs at runtime. Have a look at:
WixBootstrapper
WixBootstrapper_UI
WixBootstrapper_NoUI

You can also have a look at the earlier attempts to solve the same challenge (before Bootstrapper support was released):
Simplified Bootstrapper
NativeBootstrapper

However, if you already have the solution and only want to untangle the blocked vcredist install, you can just make a non blocking Process.Start call from AfterInstall to a vcredist launcher, which you can distribute along with your vcredist:

Pseudo code:
_crt_launcher.exe_
```C#
static void Main()
{
while(Process.getProcessByName("msiexec").Any())
Thread.Sleep(1000);

var vcredist = Assembly.GetExecutingAssembly.Location.GetDirName().PathCombine("vcredist.exe");
Process.Start(vcredist);

}

_setup.msi_
```C#
project.AfterInstall += Project_AfterInstall;
...
private static void Project_AfterInstall(SetupEventArgs e)
{
    if (e.IsInstalling)
        Process.Start(e.InstallDir.PathCombine("crt_launcher.exe"));
    ...

It's not a complete substitution for bootstrapping but for all practical reasons may be just fine.

Dear Oleg
thanks for your reply... I've changed my mind and decided to use the msm packages from Microsoft to merge them with my installation module. I think it should be possible using the _Merge_ class in WixSharp.

Fair enough.

Juts keep in mind that Merge Modules are even more conservative approach than MSI itself. Even MS completely ditch them in all MS current products. E.G. Visual Studio and Office are using bootstrappers only to manage packages installations.

Saying that, it does not mean that msm may not work just fine on the case by case base.

VS2019 has no MSM modules for VCredist things. See https://github.com/MicrosoftDocs/cpp-docs/issues/2248
... edit ... yes, it does but MSMs aren't much fun so I didn't.

Here is what worked for me for the latest VC16 (actually VC14) runtime ...

````csharp
static void Msi_AfterInstall(SetupEventArgs e)
{
if (e.IsInstalling)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64");
string crtVersion = (string)registryKey?.GetValue("Version");

    if (string.Compare(crtVersion , "v14.26.28720.03") > -1)
        return;

    Process.Start(e.InstallDir.PathCombine("vcredist_x64.exe"), "/install /passive /norestart");
}
// https://github.com/oleg-shilo/wixsharp/issues/331#issuecomment-379198014

}
````

Was this page helpful?
0 / 5 - 0 ratings