因为项目需要,最近在研究Wix打包部署,园子里也有一些关于wix的博客,方方面面,讲的点各不同。我自己也在测试过程中,写下过程,以供参考。最新版本WiX Toolset v3.7,如何安装的就不说了,可以参考 http://blog.csdn.net/rryqsh/article/details/8274832
打包关心的问题有 1).Net版本检查 2)桌面和菜单栏的快捷方式 3)更换图标画面,进度条 4)自动打包 5)自动更新版本。6)安装目录和细节 带着问题去探索,欢迎补充。先走通一个简单的Demo,再回头看概念。
第一个Wix set Up
1.先创建一个简单的Winform程序
2. 在解决方案中右键添加新项目,选择Windows Installer XML(前提你要安装了wix Toolset v3.7),再选择Setup Project,修改项目名称,确定。
这样子,解决方案下面会多一个Setup07的工程,这个工程下面有一个Product.wxs 文件,默认已经打开,这是一个XML文件,也就是工程的配置文件,初次看上去各种元素不知所云,先不管,先需要修改三个地方,首先需要引入MyApplication,
在第三行有一个Product元素,需要在Manfacturer中加入你或者你公司的名字。
<Product Id="*" Name="Setup07" Language="1033" Version="1.0.0.0" Manufacturer="RJStone" UpgradeCode="3486eddf-0957-45cf-8c26-3de8bceca2b4">
再在最下方有一个Fragment元素块,修改为
添加了这么一段
<Component Id="ProductComponent"> <File Source="$(var.MyApplication.TargetPath)" /> </Component>
完成之后,生成一下,这样第一个简单的wix打包文件已经在SetUp07的bin/debug下面生成了。
点击Setup07.msi 就可以安装了。 但这个时候的安装很快,因为比较简单不会有什么进度条,上一步下一步的,安装完成之后桌面和菜单栏中都没有图标,因为你还没有配置让它有。但在c盘下的Rrogram Files(X86)下面可以找到Setup07这个文件夹,打开他里面就是Myapplication的exe。可以执行。
还有一个问题就是,只要改变一次这个Myapplication ,重新生成,那么打包文件也会自动生成一个新的,如果你没有改变,只是重复点生成,打包文件是不会更新的。这其实就是借助了MSBuild的机制,自动生成打包文件。当然这个程序的卸载目前就去控制面板中手动卸载吧。
初步认识Wix
1)MSBuild 是 Microsoft Build Engine 的缩写,代表 Microsoft 和 Visual Studio 的新的生成平台,引入了一种基于xml的文件格式。他负责生成exe文件,需要生成打包文件需要wix, MSBuild 园子知识库的简解 http://kb.cnblogs.com/page/45681/
wix官方文档说:用Msbulid生成wix,需要创建一个.wixproj 的文件,其实这个文件上面的Setup07中VS已经帮我们自动生成,只是要打开文件夹才能看到。
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">x86</Platform> <ProductVersion>3.7</ProductVersion> <ProjectGuid>384a3edb-dbda-4948-9071-ae6a05968f55</ProjectGuid> <SchemaVersion>2.0</SchemaVersion> <OutputName>Setup07</OutputName> <OutputType>Package</OutputType> <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath> <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <OutputPath>bin\$(Configuration)\</OutputPath> <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> <DefineConstants>Debug</DefineConstants> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <OutputPath>bin\$(Configuration)\</OutputPath> <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> </PropertyGroup> <ItemGroup> <Compile Include="Product.wxs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\MyApplication\MyApplication.csproj"> <Name>MyApplication</Name> <Project>{b16ec091-efc7-4cd3-b62b-eec13303d72a}</Project> <Private>True</Private> <DoNotHarvest>True</DoNotHarvest> <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups> <RefTargetDir>INSTALLFOLDER</RefTargetDir> </ProjectReference> </ItemGroup> <Import Project="$(WixTargetsPath)" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Wix.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>