问题
So far (thanks to a post from Rob Mensching), my code will detect .NET 4.0 if it's installed, and it'll pass right over it. I'm not able to correctly detect Microsoft Visual C++ 2010 x86 Redistributable OR Microsoft SQL Server Compact 3.5 Service Pack 2.
My code is below. I'm learning, so I would appreciate as much constructive criticism as possible.
<!-- Search for .NET 4.0 -->
<util:RegistrySearch Id="NETFRAMEWORK40"
Root="HKLM"
Key="SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full"
Value="Install"
Variable="NETFRAMEWORK40"
Result="value"/>
<!-- Search for Microsoft Visual C++ 2010 x86 Redistributable -->
<util:RegistrySearch Id="SearchForCPP2010X86"
Root="HKLM"
Key="SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x86"
Value="Install"
Variable="CPP2010Redist"
Result="exists"/>
<!-- Search for Microsoft SQL Server Compact 3.5 Service Pack 2 -->
<util:RegistrySearch Id="SearchForSQLSvrCE35SP2"
Root="HKLM"
Key="SOFTWARE\Microsoft\Microsoft SQL Server Compact Edition\v3.5\ENU"
Value="Install"
Variable="SQLSvrCE35SP2"
Result="exists"/>
<Chain>
<!-- Install .NET 4 Full -->
<PackageGroupRef Id="Net4Full"/>
<!-- Install Microsoft Visual C++ 2010 x86 Redistributable -->
<PackageGroupRef Id="MSVisCPP2010x86Redist"/>
<!-- Install Microsoft SQL Server Compact 3.5 Service Pack 2 -->
<PackageGroupRef Id="SQLExpressCE"/>
</Chain>
<!-- Install .NET 4.0 -->
<PackageGroup Id="Net4Full">
<ExePackage Id="Net4Full"
Name="Microsoft .NET Framework 4.0 Setup"
Cache="no"
Compressed="yes"
PerMachine="yes"
Permanent="yes"
Vital="yes"
SourceFile="BootstrapperLibrary\dotNetFx40_Full_setup.exe"
DetectCondition="NETFRAMEWORK40"/>
</PackageGroup>
<!-- Install Microsoft Visual C++ 2010 x86 Redistributable -->
<PackageGroup Id="MSVisCPP2010x86Redist">
<ExePackage Id="MSVisCPP2010x86Redis"
Name="Microsoft Visual C++ 2010 x86 Redistributable "
Cache="no"
Compressed="yes"
PerMachine="yes"
Permanent="yes"
Vital="yes"
SourceFile="BootstrapperLibrary\vcredist_x86.exe"
DetectCondition="CPP2010Redist"/>
</PackageGroup>
<!-- Install Microsoft SQL Server Compact 3.5 Service Pack 2 -->
<PackageGroup Id="SQLExpressCE">
<ExePackage Id="SQLExpressCE"
Name="Microsoft SQL Server Compact 3.5 Service Pack 2 Setup"
Cache="no"
Compressed="yes"
PerMachine="yes"
Permanent="yes"
Vital="yes"
SourceFile="BootstrapperLibrary\SSCERuntime-ENU.exe"/>
</PackageGroup>
回答1:
I was able to come up with the following solution. It's not ideal, but it works for now. We were given a very short amount of time to come up with something, so this is what "works" for now.
I had to go back to the documentation several more times and eventually discovered what I needed and what I was doing wrong. Again, this is an "it works sort of" solution to my problem.
WiX manual
WiX tutorial
I was also able to get a copy of the book "WiX 3.6: A Developer's Guide to Windows Installer XML" which proved to be useful. It would have been extremely useful, had it been available from day one.
My only complaint with the online WiX tutorial is that it does not have a copy (that I could find) that is based here in the US. I had to submit a request to have the website approved through our network security department. I now have access, but I had to wait a day to utilize it. When you're on a very tight development cycle, one day is a big deal.
Originally, part of my story was to search for both the 32- and 64-bit versions of SQL Server CE. I had a little trouble with the 64-bit version and ran out of time, so I used the attached file to download both the 32- and 64-bit installation files when applicable.
<!--Search for .NET 4.0-->
<util:RegistrySearch Id="NETFRAMEWORK40"
Root="HKLM"
Key="SOFTWARE\Microsoft\Net Framework Setup\NDP\v4\Full"
Value="Install"
Variable="NETFRAMEWORK40"
Result="value"/>
<!--Search for Microsoft Visual C++ 2010 x86 Redistributable-->
<util:RegistrySearch Root="HKLM"
Key="SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x86"
Variable="CPP2010Redist"
Value="Installed"
Result="value"/>
<!--Search for Microsoft SQL Server Compact 3.5 Service Pack 2 x86-->
<util:RegistrySearch Id="SqlCeRegistryx86"
Root="HKLM"
Key="SOFTWARE\Microsoft\Microsoft SQL Server Compact Edition\v3.5\ENU"
Variable="SQLSvrCE35SP2x86"
Win64="no"
Result="exists"/>
<Chain>
<!-- Install .Net 4 Full -->
<PackageGroupRef Id="Net4Full"/>
<!-- Install Microsoft Visual C++ 2010 x86 Redistributable -->
<PackageGroupRef Id="MSVisCPP2010x86Redist"/>
<!-- Install Microsoft SQL Server Compact 3.5 Service Pack 2 x86 -->
<PackageGroupRef Id="SQLExpressCEx86"/>
</Chain>
<Fragment Id="Prerequisites">
<!--.NET 4.0-->
<PackageGroup Id="Net4Full">
<ExePackage Id="Net4Full"
Cache="no"
Compressed="yes"
PerMachine="yes"
Permanent="yes"
Vital="yes"
SourceFile="BootstrapperLibrary\dotNetFx40_Full_setup.exe"
DetectCondition="NETFRAMEWORK40"/>
</PackageGroup>
<!--Microsoft Visual C++ 2010 x86 Redistributable-->
<PackageGroup Id="MSVisCPP2010x86Redist">
<ExePackage Id="MSVisCPP2010x86Redist"
Cache="no"
Compressed="yes"
PerMachine="yes"
Vital="yes"
SourceFile="BootstrapperLibrary\vcredist_x86.exe"
DetectCondition="CPP2010Redist"/>
</PackageGroup>
<!--Microsoft SQL Server Compact 3.5 Service Pack 2 x86-->
<PackageGroup Id="SQLExpressCEx86">
<ExePackage Id="SQLExpressCEx86"
Cache="no"
Compressed="yes"
PerMachine="yes"
Vital="yes"
SourceFile="BootstrapperLibrary\SSCERuntime-ENU.exe"
DetectCondition="SQLSvrCE35SP2x86"/>
</PackageGroup>
回答2:
Surely, detection is the job of the redistributable. I would only try to reproduce it myself if the redistributable was known to have scenarios with undesirable behaviors (that is, is broken). Even then I would look for official documentation first.
Microsoft's Aaron Stebner's say in his personal blog:
Overall, my recommendation for the VC++ redistributable packages is to not bother to try to detect if the package is already installed. Instead, I recommend that you always install them during your installation process.
Your installer's declared goal is for the end state of VC 2010 runtime libraries to be functional at a certain service pack level. It communicates this goal to the redistributable, and it (hopefully) achieves it efficiently through whatever installation and/or repair process it deems necessary.
The key things to get right in an ExePackage are the InstallCommand
and ExitCode
s. Ideally, these would be officially documented. Exit codes are somewhat standardized to indicate failure, success with reboot required now, success with now reboot required (see the first note).
来源:https://stackoverflow.com/questions/23943920/wix-bootstrapper-difficulty-detecting-if-software-is-already-installed-c-red