title: Including .NET installer in WiX Bundle not detecting if already installed
body: <p>I'm on WiX 3.7, and I can't get the simple &lt;PackageGroupRef Id="NetFx40Web"/> bundle element to work, as it doesn't bring across the Net FX installer package, or embed it in the setup.exe. I've resorted to creating my own package for this in my <code>Bundle.wxs</code> file, but I am still having trouble. It seems to always try to install .NET 4, even if the machine already has .NET installed.</p>
  
  <p>I'm not quite sure of the difference between <em>InstallCondition</em> and <em>DetectCondition</em>. I think <em>InstallCondition</em> is used to install the package if the evaluation is true, otherwise uninstall it. How does this work with things that are typically <em>permanent=yes</em>, such as most pre-requisites? <em>DetectCondition</em> is almost the opposite, I think, in that it checks if it's already on the system, and if so, doesn't install it.</p>
  
  <p>Below is my full <code>Bundle.wxs</code> file which is in a Visual Studio WiX Bootstrapper project. I'm attempting to look at the registry and scope out of .NET 4.0 registry key is there. If it is present, then I don't want to install .NET 4., and if it's not there, then install it. But, this isn't working, and it always attempts to install .NET.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
      &lt;Bundle
          Name="MyProgramBootstrapper"
          Version="1.0.0.0"
          Manufacturer="Microsoft"
          UpgradeCode="{2299B51D-9FD8-4278-90C8-2B79DB37F402}"&gt;
  
          &lt;BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" /&gt;
          &lt;Chain&gt;
            &lt;PackageGroupRef Id="Netfx4Full"/&gt;
            &lt;MsiPackage
                Id="MyProgramInstaller"
                SourceFile="$(var.MyProgramInstaller.TargetPath)"
                Compressed="no"/&gt;
          &lt;/Chain&gt;
      &lt;/Bundle&gt;
  
      &lt;Fragment&gt;
          &lt;Property Id="NET40_FULL_INSTALL_32"&gt;
              &lt;RegistrySearch
                  Id ="SearchNet40_32bit"
                  Root="HKLM"
                  Key="SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full"
                  Name="Version"
                  Type ="raw"/&gt;
          &lt;/Property&gt;
          &lt;Property
              Id="NET40_FULL_INSTALL_64"&gt;
  
              &lt;RegistrySearch
                  Id ="SearchNet40_64bit"
                  Root="HKLM"
                  Key="SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full"
                  Name="Version"
                  Type ="raw"
                  Win64="yes" /&gt;
          &lt;/Property&gt;
  
          &lt;WixVariable
              Id="WixMbaPrereqPackageId"
              Value="Netfx4Full" /&gt;
          &lt;WixVariable
              Id="WixMbaPrereqLicenseUrl"
              Value="NetfxLicense.rtf" /&gt;
          &lt;PackageGroup
              Id="Netfx4Full"&gt;
            &lt;ExePackage
                Id="Netfx4Full"
                Cache="no"
                Compressed="no"
                PerMachine="yes"
                Permanent="yes"
                Vital="yes"
                SourceFile="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\DotNetFX40\dotNetFx40_Full_x86_x64.exe"
                DetectCondition="NET40_FULL_INSTALL_32 OR NET40_FULL_INSTALL_64"
                DownloadUrl="http://go.microsoft.com/fwlink/?LinkId=164193"/&gt;
          &lt;/PackageGroup&gt;
      &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>Bootstrapper installer log:</p>
  
  <pre><code>[010C:2FB0][2013-05-10T12:07:07]w120: Detected partially cached package: Netfx4Full, invalid payload: Netfx4Full, reason: 0x80070570
  [010C:2FB0][2013-05-10T12:07:07]i052: Condition 'NETFRAMEWORK40' evaluates to false.
  [010C:2FB0][2013-05-10T12:07:07]w120: Detected partially cached package: MyInstaller, invalid payload: f4832BA0972BDE9B6FA8A19FBB614A7BA, reason: 0x80070570
  [010C:2FB0][2013-05-10T12:07:07]i101: Detected package: Netfx4Full, state: Absent, cached: Partial
  </code></pre>
  
  <hr/>
  
  <p>Update, with solution. I used the built-in WiX RegistrySearch to determine if it's installed. I had to reference the WixUtilExtension.dll in my Bundle project. Here's the updated Bundle.wxs:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
      xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension"
      xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
  &gt;
      &lt;Bundle
          Name="MyProgramBootstrapper"
          Version="1.0.0.0"
          Manufacturer="Microsoft"
          UpgradeCode="{2299B51D-9FD8-4278-90C8-2B79DB37F402}"&gt;
  
          &lt;BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" /&gt;
          &lt;Chain&gt;
              &lt;PackageGroupRef Id="Netfx4Full"/&gt;
              &lt;!-- TODO: Define the list of chained packages. --&gt;
                    &lt;!-- &lt;MsiPackage SourceFile="path\to\your.msi" /&gt; --&gt;
              &lt;MsiPackage
                  Id="MyProgramInstaller"
                  SourceFile="$(var.MyProgramInstaller.TargetPath)"
                  Compressed="no"  /&gt;
          &lt;/Chain&gt;
      &lt;/Bundle&gt;
  
      &lt;Fragment&gt;
          &lt;util:RegistrySearchRef Id="NETFRAMEWORK40"/&gt;
          &lt;PackageGroup
              Id="Netfx4Full"&gt;
  
              &lt;ExePackage
                  Id="Netfx4FullExe"
                  Cache="no"
                  Compressed="no"
                  PerMachine="yes"
                  Permanent="yes"
                  Vital="yes"
                  SourceFile="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\DotNetFX40\dotNetFx40_Full_x86_x64.exe"
                  InstallCommand="/q /norestart /ChainingPackage FullX64Bootstrapper"
                  DetectCondition="NETFRAMEWORK40"
                  DownloadUrl="http://go.microsoft.com/fwlink/?LinkId=164193"/&gt;
          &lt;/PackageGroup&gt;
      &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>