如何将依赖 .dll 文件与 WiX 中的主要产品捆绑在一起

How to bundle dependency .dll files with main product in WiX

我正在为具有许多依赖项的 .NET 项目创建一个 wix 安装程序。目前,我有一个可用的 .msi 安装程序,但正如预期的那样,所有依赖项 .dll(以及资源​​文件夹)都放在与安装的应用程序相同的目录中,而不是与它捆绑在一起。

阅读 WIX Bundle Creation 的答案,似乎可以将我的产品保持在一个文件中,并在另一个文件中包含引用该产品的 Bundle,但我似乎找不到这方面的任何示例。

有没有简单的方法可以做到这一点?我在下面包含了产品代码的概要。

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:ui="http://schemas.microsoft.com/wix/UIExtension">  
    <Product Id="*" Name="#####" Language="1033" Version="1.0.0.0" Manufacturer="..." UpgradeCode="...">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Platform="x64"/>

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
    <UIRef Id="WixUI_InstallDir" />

        <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes"/>

        <Feature Id="ProductFeature" Title="alphaInstaller" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
            <ComponentGroupRef Id="ProductMenuComponents" />
            <ComponentGroupRef Id="DependencyComponents"/>
            <ComponentGroupRef Id="ResourcesComponents"/>
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
         <Directory Id="ProgramMenu64Folder">
            ...
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
          <Component Id="CMP_alphaGUISetup" Win64="yes">
             <File Id="FILE_alphaGUIApplication.exe" Source="$(var.alphaGUI.TargetPath)" KeyPath="yes"></File>
          </Component>
        </ComponentGroup>
    <ComponentGroup Id="ProductMenuComponents" Directory="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="..." >
        <Shortcut .../>
        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
        <RegistryValue .../>
      </Component>
    </ComponentGroup>
    <ComponentGroup Id="DependencyComponents" Directory="INSTALLFOLDER" Source=...>
      <Component Id="log4net">
        <File Name="log4net.dll" />
      </Component>
        ...
    </ComponentGroup>
    <ComponentGroup Id="ResourcesComponents" Directory="ResourcesFolder" Source=...>
      <Component Id="logo.ico">
        ...
    </ComponentGroup>
    </Fragment>
</Wix>

请将 Media Element 添加到包元素正下方的 WXS 文件中,这样应该可以解决问题。

<Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />

Single-file-deployment?:我有点不确定这是不是你问的,但看起来你想将所有 dll 嵌入到单个 .NET 可执行文件中?


Ilmerge.exe这不是我的专业领域,但是有这个答案:Embedding DLLs in a compiled executable that you can check out. The tool Ilmerge.exe - how-to(另见下面的答案)。模型:

ILMerge.exe /target:winexe /out:All.exe Main.exe one.dll two.dll

我从来没有用过这个。如果它适用于所有情况,我会感到非常惊讶。明显地。值得一试?使用 virustotal.com(发布模式二进制文件)测试合并的二进制文件以确定是否触发任何恶意软件警告。

资源文件嵌入:您还可以在一个文件中嵌入资源文件,例如图像、html模板和其他内容.NET 可执行文件,如果这是您想要的。这是我能找到的最简洁的模型 (source):

  • 添加文件 TestFile.txt作为嵌入资源:Project Menu>> Properties >> Resources >> Add Existing file.

  • 代码访问:string queryFromResourceFile = Properties.Resources.Testfile.ToString();

Shared Project:对于 .NET 项目/C# 类型,有难以捉摸的“”被编译成您在构建时的主要可执行文件。不确定这种项目类型是什么时候出现的。它存在于 VS2017 中。

单个项目选项:您显然也可以将所有代码文件移动到同一个项目中,然后以这种方式编译可执行文件。除非您打算将所有源文件永久保存在一个项目中,否则我不会这样做。否则你会得到一个非常愚蠢的构建过程?我想所有的选项都应该被提及,所以我们记住或承认它们为什么不好。

更多选择?:我相信还有更多选择。可能是我不知道的编译器的一些标志。有知道的请补充。 在youtube上发现了这种有点疯狂的做法(设置dll资源嵌入到Visual Studio项目中,然后添加代码读取嵌入的程序集)。不知杀毒软件是如何判断后者的?使用 virustotal.com(发布模式二进制文件)进行测试。我猜与 Ilmerge.exe 合并的二进制文件也是如此。


链接:

  • How to merge multiple assemblies into one?
  • Embedding DLLs in a compiled executable