How to execute a WiX custom action DLL file with dependencies

前端 未结 4 1956
生来不讨喜
生来不讨喜 2020-12-14 16:55

I want to create a CustomAction C# DLL file that depends on a third-party .NET DLL (in this specific case, it\'s MySql.Data.dll). I have the C# custom action DL

相关标签:
4条回答
  • 2020-12-14 17:41

    DTF in the WiX toolset has a mechanism to include your custom action assembly and all of its references into a single binary (self-extracting dll, basically). I don't write managed custom actions (C/C++ creates custom actions with fewer dependencies and increases success rate) but it is supposed to just work when building in VS.

    0 讨论(0)
  • 2020-12-14 17:49

    You can use <Binary /> to add whatever files are needed to run custom actions. That should go for any 3rd party dlls you require too. Files included using the binary element are only used during installation and will not be regarded as part of the application being installed.

    Update: the connection between a CustomAction and a Binary is done by referencing the binary from the custom action using the BinaryKey attribute.

    Unless you can have multiple BinaryKey attributes (I have not tried this and does not directly see any support for this in the MSI custom action table) you can only have a custom action depending on one binary. That binary will thus need to carry all necessary dependencies within itself.

    That said, if your dlls are all .Net assemblies, an idea would be to use ILMerge to package them into one single assembly.

    0 讨论(0)
  • 2020-12-14 17:54

    Following on Mr. Mensching's comment, I will fill in a little more detail.

    Assuming you're on at least Wix 3.0, you can use MakeSfxCA.exe to package dependencies in a single DLL. (This was an add-in from the DFT -- Deployment Tools Foundation.) Basically, start off by making sure project is copying your dependent DLLs. Make a CustomAction.config file. Test with a simple .bat file like:

    REM MyMakeSfxCA.bat - Run under $(TargetDir); abs. paths reqd.
    "%WIX%\SDK\MakeSfxCA" ^
        %cd%\Managed_custom_action_pkg.dll ^
        "%WIX%\SDK\x86\sfxca.dll" ^
        %cd%\Managed_custom_action.dll  ^
        %cd%\Dependent1.dll ^
        %cd%\Dependent2.dll ^
        %cd%\Microsoft.Web.Administration.dll ^
        %cd%\Microsoft.Deployment.WindowsInstaller.dll ^
        %cd%\CustomAction.config 
    

    Once that works, convert into a Post-Build Event:

    "$(WIX)\SDK\MakeSfxCA" ^
        $(TargetDir)\Managed_custom_action_pkg.dll ^
        "$(WIX)\SDK\x86\sfxca.dll" ^
        $(TargetDir)\Managed_custom_action.dll  ^
        $(TargetDir)\Dependent1.dll ^
        $(TargetDir)\Dependent2.dll ^
        $(TargetDir)\Microsoft.Web.Administration.dll ^
        $(TargetDir)\Microsoft.Deployment.WindowsInstaller.dll ^
        $(TargetDir)\CustomAction.config
    

    In your .wxs file, your Binary Key will look like:

    <Binary Id="Managed_custom_action_CA_dll" 
            SourceFile="$(var.Managed_custom_action.TargetDir)$(var.Managed_custom_action.TargetName)_pkg.dll" />
    

    For they CustomAction.config, you can find examples online.

    This is the best way that I've found.

    0 讨论(0)
  • 2020-12-14 17:56

    Set 'Copy Local' property on the hard reference to True in Visual Studio.

    0 讨论(0)
提交回复
热议问题