Wix创建msi安装包, 批量包含文件或包含指定文件夹

简介桌面安装包越来越少用, wix打包的使用者更少, 简单记录下wix打包自动导入多文件的解决方案

冷门技术,写着就没啥动力.

–怎样使用Wix制作msi安装包
1.下载VS拓展, https://wixtoolset.org/releases/
2.新建wix的项目, 后缀.wixproj的项目
3.引入需要打包的项目
4.添加wsx文件, 类似下面的结构
5.

<?xml version="1.0" encoding="UTF-8"?> <?define Initialization = "LZH"?> <?define ProductCode = "{D4A2CFFB-405A-4E46-9FF7-488BB7ADDDE3}"?> <?define UpgradeCode = "{F0CECB22-F934-463B-B8BD-EB7F36EB9FF7}"?> <?define ProductName = "CandidateClient"?> <?define ProductVersion="!(bind.fileVersion.fil57FE6F2BDD5954F69C2D9EF36BB4411C)" ?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:fw='http://schemas.microsoft.com/wix/FirewallExtension' xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> <Product Id="*" Name="BC.VCS.CandidateClientSetup" Language="1033" Version="$(var.ProductVersion)" Manufacturer="BritishCouncil.org" UpgradeCode="$(var.UpgradeCode)"> <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> <MediaTemplate EmbedCab="yes" /> <WixVariable Id="VCS_SOURCE" Value="$(var.BC.RS.CandidateClient.TargetDir)" /> <WixVariable Id="WixUILicenseRtf" Value="License.rtf" /> <!-- 不允许安装旧版本 --> <MajorUpgrade AllowDowngrades="no" AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of $(var.ProductName) is already installed." /> <UI> <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" /> <UIRef Id="WixUI_InstallDir" /> </UI> <Feature Id="CandidateClient" Title="CandidateClient" Level="1"> <ComponentGroupRef Id="ClientSource" /> <ComponentRef Id="AppDesktopShortcut" /> </Feature> </Product> <!--导入一些项目文件--> </Wix>

Wix的项目默认不会包含项目中的所有文件, 挨个手动添加到 wsx 不现实,可以使用下面方式

在wix项目.wixproj文件中,添加下面方式中的一种

  1. 使用heat.ext
<Target Name="BeforeBuild"> <Exec Command='"$(WixExtDir)\heat.exe" dir "$(SolutionDir)BC.RS.CandidateClient\Bin\$(Platform)\$(Configuration)" -var wix.SOURCE -cg Package -dr INSTALLFOLDER -srd -gg -sfrag -template fragment -out "Source.wxs"' /> <ItemGroup> <Compile Include="Source.wxs" /> </ItemGroup> </Target>
  1. 使用HeatDirectory
<Target Name="BeforeBuild"> <HeatDirectory OutputFile="Source\VCS_SOURCE.wxs" DirectoryRefId="INSTALLFOLDER" SuppressCom="true" Directory="项目文件路径" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" PreprocessorVariable="wix.VCS_SOURCE" /> <ItemGroup> <Compile Include="Source\VCS_Source.wxs" /> </ItemGroup> </Target>

怎样排除一些文件
创建一个 Ext.xsl 文件, 如下

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wi="http://schemas.microsoft.com/wix/2006/wi" xmlns="http://schemas.microsoft.com/wix/2006/wi"> <xsl:template match="wi:Component[( contains(concat(wi:File/@Source,'|'), 'BC.1.exe|') or contains(concat(wi:File/@Source,'|'), 'BC.2.exe|'))]"> </xsl:template> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>

在上个环节的命令中,添加 -T Ext.xsl 即可.

代码里面的一些字段作用懒得写了,遇到问题可以联系我.

参考网站:

  1. https://nblumhardt.com/2017/04/netcore-msi/
  2. https://documentation.help/WiX/
  3. msbuild 相关内容
    https://documentation.help/WiX/msbuild_task_reference_light.htm

本站发布的文章受知识共享协议保护,转载、收录请标明出处。

评论


昵称:   邮箱:

Top