Do Pre-checking before install

用户有了快捷方式了,但当程序启动起来后,却弹出一个错误说"应用程序正常初始化(0xc0000135)失败.请单击'确定',终止应用程序."...

晕了,原来客户的机器上没装.NET Framework啊~一般这种情况下,没耐心的用户会大骂一通,然后直接卸载走人~这是我们最不愿意看到的,那么在安装前,怎样告诉用户这个有可能引发他不满的信息呢?解决方案,WiX已经准备好了~来看下面这段代码节选:
代码
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">

    ......

<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    
<PropertyRef Id="NETFRAMEWORK35"/>
    
<Condition Message="This application requires .NET Framework 3.5. Please install the .NET Framework then run this installer again.">
      
<![CDATA[Installed OR NETFRAMEWORK35]]>
    
</Condition>

<Directory Id="TARGETDIR" Name="SourceDir">

......
注意1) 除了声明命名空间(xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension")外,还得在WiXProject中添加WixNetFxExtension的引用

2) "NETFRAMEWORK35"是一个在WixNetFxExtension中预定义的Property,当系统安装有.Net 3.5时,它的值被设置成"#1".当然还有很多其他有用的属性,具体请参考C:\Program Files\Windows Installer XML v3\doc\WiX.chm::/html/wixnetfxextension.htm

 

接下来,我们详细看看Condition

<Condition Message="This application requires .NET Framework 3.5. Please install the .NET Framework then run this installer again.">
   
<![CDATA[Installed OR NETFRAMEWORK35]]>
</Condition>
<Condition>1) Message是在计算条件"Installed OR NETFRAMEWORK35"得出false的情况下,才会弹出并终止安装的.

2) 换句话说,这里的"表达式"是确保安装能够顺利进行的必要条件,按照优先级用"OR"连接,不是产生Error Message的条件!

3) 所以你写"Installed OR NETFRAMEWORK35"的意思是

if (Installed)
{
  
if (NETFRAMEWORK35)
    PASS;
  
else
    ERROR;
}
else
  PASS;

4) Installed 是Windows Installer的预定义属性,标示当前产品是否已经被安装过.和NETFRAMEWORK35一样有值则表示True


好了,我们在看看其他几个经常用到的Pre-checking

OS Version
<Condition Message="This application only runs on Windows XP or higher.">
  
<![CDATA[Installed OR (VersionNT >= 501)]]>
</Condition>
Privileged
<Condition Message="You need to provide Administrator permission in order to install this product.">
  Privileged
</Condition>

"<![CDATA[Privileged]]>"两个都可以~


Condition的不仅仅用在Pre-checking,条件也是可以是自定义的任意属性组合~ 这些我们以后遇到具体问题再加以介绍~

 

Pre-checking对一个良好的Installer来说非常重要,那种写在Readme.txt里的真不如冒昧的弹出个对话框!用户都希望把问题解决在萌芽之中,而不是事后截图,发帖子在你的产品支持论坛里~

posted @ 2009-12-22 23:47  shalahu  阅读(1141)  评论(0编辑  收藏  举报