通过之前三篇的介绍,大家对wix的xml部署方式也应该有一些认识,今天天气不错,再来一发。主要介绍桌面,开始菜单,卸载等功能的如何添加。希望园友们支持!
一、如何添加文件
Demo打包程序很简单,就一个exe,但实际过程中,往往还要引用一些dll,配置文件。我们如何安装到目标文件下呢。这个就比windows installer 麻烦些了,在windows installer中直接一个添加引用就可以了。 但wix也不麻烦,首先要明白各个元素的作用,Directory定义了安装目录,ComponentGroup和DirectoryRef包含的Component和File 定义文件的正真的路径。然后Feature 就是一个安装清单,告诉wix需要安装的文件是哪些。 我们试着在安装目录下增加一个文件,放入一个dll和一个xml文件。
1.先在wix工程中新建一个文件夹,把我们需要打包的文件copy进来。
2.再修改目标文件夹。在Setup07下面加入一个Id="Demo"的Directory
<Fragment> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="INSTALLFOLDER" Name="Setup07" > <Directory Id="Demo" Name="Demo" /> </Directory> </Directory> </Directory> </Fragment>
3.定义需要添加的文件的位置。在Framment 元素块。添加一个DriectoryRef 元素,id指向Demo,
<Fragment> <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> <Component Id="ProductComponent"> <File Id="myapplication.exe" Source="$(var.MyApplication.TargetPath)" /> </Component> </ComponentGroup> <DirectoryRef Id="Demo"> <Component Id="Variable.xml" Guid="5E254682-DD5F-453D-8333-844457282026"> <File Id="Variable.xml" Source="content/Variable.xml" /> <File Id="mydll" Source="content/CxIODrvWrapper.dll" /> </Component> </DirectoryRef> </Fragment>
如果想保持文件,在卸载的时候不被删除,用Permanent
<Component Id='keepfile' Guid='{031FD8D4-CCD9-446B-B876-F20816DFAB39}' Permanent='yes' > <File Source='$(var.Dev)IOServer\msvcr110d.dll' Id='msvcr110d' /> </Component>
我们可以看见,对于ComponentGroup直接用的是Dirctory属性INSTALLFOLDER指向上个Fragment中的Directory。他其中的file都可以安装在Setup07文件夹下。而我们的DirectoryRef 的Id指向我们创建的Demo文件夹,这里要说明的是Component 安装组件的意思,是必须和feature元素对应起来的,且其中可以包含多个File。然后修改我们的Feature元素。添加一段。关于Guid,直接在VS -工具-创建GUID 再copy出来就行。 不用每次都那么生成,把生产的随便改几个数字也行。
<ComponentRef Id="Variable.xml"/>
这个ComponentRef就直接对应了id为Variable.xml的Component的元素,告诉wix 需要安装一个这样的组件。 这样在生成就可以安装了。在你的C:\Program Files (x86)\Setup07\Demo 目录下就可以看见dll和xml文件了。
上面的ComponentGroup也可以改掉。 效果一样。
<Fragment> <!--<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> <Component Id="ProductComponent"> <File Id="myapplication.exe" Source="$(var.MyApplication.TargetPath)" /> </Component> </ComponentGroup>--> <DirectoryRef Id="INSTALLFOLDER"> <Component Id="myapplication.exe" Guid="5E254682-DD5F-453D-8323-844457212026"> <File Id="myapplication.exe" Source="$(var.MyApplication.TargetPath)" /> </Component> </DirectoryRef> <DirectoryRef Id="Demo"> <Component Id="Variable.xml" Guid="5E254682-DD5F-453D-8333-844457282026"> <File Id="Variable.xml" Source="content/Variable.xml" /> <File Id="mydll" Source="content/CxIODrvWrapper.dll" /> </Component> </DirectoryRef> </Fragment> ....... <Feature Id="ProductFeature" Title="Setup07" Level="1"> <!--<ComponentGroupRef Id="ProductComponents" />--> <ComponentRef Id="Variable.xml"/> <ComponentRef Id="myapplication.exe"/> </Feature>