2013-04-04 4 views
2

J'ai un scénario pour installer deux paquets MSI avec un seul paquet MSI.Comment installer deux packages MSI avec un package MSI unique à l'aide de WIX?

Par exemple, nous avons deux produits à installer. Sample1.MSI et Sample2.MSI. Nous devons intégrer le package Sample2.MSI dans Sample1.MSI. Si nous installons Sample1.MSI, il devrait installer à la fois Sample1.MSI et Sample2.MSI et cela devrait créer deux entrées dans Ajout/Suppression de programmes (appwiz.cpl). Après une recherche, j'ai trouvé un exemple d'application qui utilise la balise 'EmbeddedChainer' qui fonctionne correctement avec l'installation. Mais il ne désinstalle pas correctement.

<Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="ProgramFilesFolder"> 
      <Directory Id="INSTALLLOCATION" Name="SampleSetup"> 

     <Component Id="InstallMSIComponent" Guid="{7091DE57-7BE3-4b0d-95D5-07EEF6463B62}"> 
     <File Id="ChainRunner.exe" Name="ChainRunner.exe" 
       Source="C:\ChainRunner.exe" 
       DiskId="1" KeyPath="yes"/> 
     <File Id="TestFile.txt" Name="TestFile.txt" Source="TestFile.txt" /> 
     <File Id="Microsoft.Deployment.WindowsInstaller.dll" Name="Microsoft.Deployment.WindowsInstaller.dll" Source="C:\Microsoft.Deployment.WindowsInstaller.dll"/> 
     <File Id="Microsoft.Deployment.WindowsInstaller.xml" Name="Microsoft.Deployment.WindowsInstaller.xml" Source="C:\Microsoft.Deployment.WindowsInstaller.xml"/>   
     <RemoveFolder Id='INSTALLLOCATION' On='uninstall' /> 
     </Component> 

     <Component Id="SampleSetup2Component" Guid="{CB568AA4-9790-4efd-91BB-82682F063321}"> 
     <File Id="SampleSetup2.msi" Name="SampleSetup2.msi" 
       Source="SampleSetup2.msi" 
       DiskId="1" KeyPath="yes"/>  
     </Component> 
      </Directory> 
     </Directory> 
    </Directory> 
<EmbeddedChainer Id="Chainer" FileSource="ChainRunner.exe"/> 

    <Feature Id="ProductFeature" Title="SampleSetup" Level="1"> 

    <ComponentRef Id="InstallMSIComponent"/> 
    <ComponentRef Id="SampleSetup2Component"/> 

     <ComponentGroupRef Id="Product.Generated" /> 
    </Feature> 

Code ChainRunner

public class CustomActions 
{ 

    static void Main(string[] args) 
    { 

     try 
     { 
      IntPtr ptr = new IntPtr(Convert.ToInt32(args[0], 16)); 
      ptr = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAuto(args[0]); 
      Transaction transaction = Transaction.FromHandle(ptr, true); 
      transaction.Join(TransactionAttributes.JoinExistingEmbeddedUI); 

      Installer.InstallProduct(@"C:\SampleSetup2.msi", ""); 
      transaction.Commit(); 
      transaction.Close(); 
     } 
     catch (Exception e) 
     { 

      Console.WriteLine("Exception in Installation:"+e.Message+"\n"+e.StackTrace.ToString()); 
      Console.ReadKey(); 
      throw e; 
     } 
    } 
    [CustomAction] 
    public static ActionResult CustomAction1(Session session) 
    { 
     session.Log("Begin CustomAction1"); 

     return ActionResult.Success; 
    } 
} 

Lorsque le cela a été foiré?

S'il vous plaît avis s'il y a un autre meilleur moyen autre que cette approche?

Répondre