如何在Wix安装包中批量获取发布目录文件并配置特定可执行文件
WiX安装包批量导入文件与特殊配置实现咨询
我们之前在WiX安装包中手动枚举所有需要打包的文件,示例代码如下:
<Component Id="Some_Files" Guid="4DC25232-0B8D-4C16-ABC9-5BD3B45D0358" SharedDllRefCount="yes"> <File Id="SomeService.dll" Name="SomeService.dll" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\SomeService.dll" /> <!-- .... --> </Component>
但随着解决方案规模扩大,每次更新NuGet包版本或新增依赖库时,都需要手动添加大量文件,效率极低。我们计划先通过Visual Studio专属SLNF发布方案(本文不展开此部分)将所有需要的文件输出到指定目录,再把该目录下的文件批量导入WiX安装包。
不过部分文件需要额外的特殊配置,比如Windows服务的安装控制:
<Component Id="Service" Guid="72044696-3E92-4928-BC6D-5A9C5FBB924A" SharedDllRefCount="yes"> <File Id="Service.exe" Name="Service.exe" KeyPath="yes" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\Service.exe" /> <ServiceInstall Id="NewServiceInstall2" Name="Service" DisplayName="Service" Type="ownProcess" Interactive="no" Start="auto" Account="LocalSystem" ErrorControl="normal" Vital="yes" /> <ServiceControl Id="Uninstall" Name="Service" Stop="both" Remove="uninstall" /> </Component>
再比如生成快捷方式和文件关联:
<Component Id="MyApp" Guid="B603887B-149F-4364-8305-EFB6CB6E2026" SharedDllRefCount="yes"> <File Id="MyApp.exe" Name="MyApp.exe" KeyPath="yes" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\MyApp.exe" > <Shortcut Id="mnuVision" Directory="solutionMenu" Name="MyApp" Description="Launch the APP" WorkingDirectory="BIN" /> </File> <ProgId Id="MyAppProject" Icon="MyApp.ico" IconIndex="0" Advertise="yes"> <Extension Id="myapp" Advertise="yes"> <Verb Id="Open" Argument=""%1"" /> </Extension> </ProgId> <!-- ... --> </Component>
现咨询以下问题:
- 能否实现「批量导入SLNF发布目录下的所有文件,同时为指定文件添加上述特殊配置」的需求?
- 如何避免文件被重复配置(比如批量导入时包含了Service.exe,又在特殊配置里重复定义)?
内容的提问来源于stack exchange,提问作者J4N
相关产品推荐
相关产品推荐

