65.9K
CodeProject 正在变化。 阅读更多。
Home

WIX Web 设置

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.05/5 (8投票s)

2007 年 5 月 4 日

4分钟阅读

viewsIcon

74639

downloadIcon

891

使用 VS2005 和 Wix 3.0 创建 WIX Web 安装程序

引言

使用 WIX 3.0 在 Visual Studio 2005 中创建 Web 安装程序。该程序还可以自动生成 wix 文件。该安装程序具有以下功能:

  • 根据环境进行安装
  • 创建事件源
  • 创建虚拟目录
  • 选择网站、应用程序池
  • 编辑配置文件

背景

根据我们项目中的一项要求,我必须实现 WIX 安装程序项目。我对部署完全是新手,努力让项目启动并运行。嗯,我应该感谢这里的教程:http://www.tramontana.co.hu/wix/ 。在本文中,我创建了一种解决方案模板,可用于在 Visual Studio 2005 中创建 Web 安装程序。它使用 .NET 2.0、Wix 3(以及用于 VS2005 集成的 votive)构建。

使用代码

* 它有什么作用?
嗯,创建带有基本自定义操作的 Web 安装程序...

* 它有什么?
它具有以下功能:
* 从 wix 脚本创建 Web 安装程序。
* ComponentWriter,写入要添加到安装程序的文件列表,升级版本号。
* Web Deployment 项目预编译 Web 项目。
* CustomInstaller 帮助创建事件源、虚拟目录、编辑配置文件(您也可以在 WDP 中完成)。

* 如何使用?
在 Web Deployment 项目中,(右键单击“打开项目文件...”)只需添加以下代码:
<!-- My customization -->
  <UsingTask AssemblyFile="..\SolutionItems\Djans.ComponentWriter.exe" TaskName="ComponentWriterTask" />
  
  <PropertyGroup>
    <SourceDirectory>$(OutputPath)</SourceDirectory>
  </PropertyGroup>
  
  <ItemGroup>
    <CustomInstallerFiles 
     Include="..\SolutionItems\Djans.CustomInstaller.dll;..\SolutionItems\Djans.CustomInstaller.dll.config"    
    />
    <EnvironmentFiles Include="..\SolutionItems\*.xml" />
  </ItemGroup>

  <ItemGroup>
    <FilesToBeDeleted Include="$(SourceDirectory)\bin\*.pdb;$(SourceDirectory)\*.csproj*" />
  </ItemGroup>

  <Target Name="AfterBuild">
    <Message Text="**************** After Build **********************" />

    <CallTarget Targets="DeleteUnwantedFiles" />
    <CallTarget Targets="CopyInstallerFiles" />
    <CallTarget Targets="CopyEnvironmentFiles" />
    <CallTarget Targets="WriteWix" />
  </Target>

  <Target Name="DeleteUnwantedFiles">
    <Message Text="Deleting unwanted Files ..." />
    <Delete  Files="@(FilesToBeDeleted)" TreatErrorsAsWarnings="true" />
    <RemoveDir Directories="$(SourceDirectory)\obj" />
  </Target>

  <Target Name="CopyInstallerFiles">
    <Message Text="Copying Installer Files ..." />
    <Copy SourceFiles="@(CustomInstallerFiles)" 
          DestinationFiles="@(CustomInstallerFiles->'$(SourceDirectory)\bin\%(Filename)%(Extension)')" />
  </Target>

  <Target Name="CopyEnvironmentFiles">
    <Message Text="Copying Environment Files ..." />
    <Copy SourceFiles="@(EnvironmentFiles)" 
          DestinationFiles="@(EnvironmentFiles->'$(SourceDirectory)\bin\%(Filename)%(Extension)')" />
  </Target>

  <Target Name="WriteWix">
    <Message Text="Writing wix files ..." />
    <ComponentWriterTask 
         SourceDirectory="$(SourceDirectory)" 
         OutputFile="..\WixSetup\Components.wxs" 
         UpgradeFile="..\WixSetup\WixSetup.wxs" 
    /> 
  </Target>
<!-- done --> 

从 target="WriteWix",调用 componentwriter 任务。它接受三个参数:源目录的位置、列出要部署的所有文件的 wix 文件以及包含 Product 元素的主 wix 文件。

ComponentWriter 列出发布目录中的所有文件,并写入 wix 组件文件。接下来,它更新 Wix 安装程序文件(主文件)中的版本代码。ComponenWriter 可以单独从命令行调用,也可以用作 msbuild 脚本中的任务。当前的 WIX 版本不会自动列出部署所需的文件。因此,我编写了一个简单的 C# 程序来完成这项工作,它将在 WIX 安装程序项目编译之前启动。在 msbuild 脚本中,样本中这是 Web Deployment 项目的一部分,它被写为:

<Target Name="WriteWix">
    <Message Text="Writing wix files ..." />
    <ComponentWriterTask 
         SourceDirectory="$(SourceDirectory)" 
         OutputFile="..\WixSetup\Components.wxs" 
         UpgradeFile="..\WixSetup\WixSetup.wxs" 
    /> 
  </Target>

ComponentWriter 任务接受三个参数:

  1. SourceDirectory: 存储源文件的目录的完整物理路径。源文件是用于部署的文件。
  2. OutputFile: 列出目录结构、要部署的文件和 feature 元素的文件。在样本中,它命名为“Component.wxs”。
  3. UpgradeFile: 这是调用 UserInterface.wxs、Actions.wxs、Component.wxs 等其他 wix 文件的主要文件。它还包含 Product、Upgrade 元素。在样本中,它是 WixSetup.wxs。
  • 注意:[UgradeFile] 仅更新前 3 部分,在 4 部分版本控制中,第 4 部分始终为 0。如果您不想使用升级,请提供“-skip”。

Screenshot - WixWebSetup.jpg


WixSetup 项目中的文件

  • Component.wxs:此文件列出了所有要部署的文件。
  • WixSetup.wxs:这是主文件,包含产品元素、版本详细信息。
  • Actions.wxs:自定义操作在此文件中定义。
  • UserInterface.wxs:这定义了安装程序的 UI 组件。
  • Properties.wxs:此文件保存安装程序的所有属性定义。
编译 Web Deployment 项目后,编译 Wix 项目,搞定!,安装程序就准备好了!

从命令行使用 ComponentWriter

开关: '?', '/?', '-?', 'help' 显示此帮助。
'-skip' 跳过升级代码的更新。

用法
ComponentWriter.exe [SourceDirectory] [OutputFile] [UgradeFile]

[SourceDirectory]:(必需)存储源文件的目录的完整物理路径。
源文件是用于部署的文件。
[OutputFile]:(必需)列出目录结构、要部署的文件和 feature 元素的文件。
[UgradeFile]:(可选)包含 upgrade 元素的文件。
要跳过使用升级,请将 '-skip' 作为参数而不是文件名提供。

示例
编写组件文件并升级版本

    Djans.ComponentWriter.exe c:\Project\Source c:\Project\WixSetup\Component.wxs c:\Project\WixSetup\WixMain.wxs
编写组件文件而不升级版本
    Djans.ComponentWriter.exe c:\Project\Source c:\Project\WixSetup\Component.wxs -skip

注意: [UgradeFile] 仅更新前 3 部分,在 4 部分版本控制中,第 4 部分始终为 0。

关注点

  • 在 Visual Studio 2005 中自动化 wix 安装程序

历史

--.

© . All rights reserved.