How to execute a WiX custom action DLL file with dependencies

二次信任 提交于 2019-12-18 11:46:06

问题


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 DLL file working with the WiX fragment below. I'm just trying to figure out how to safely add a dependency to the custom action. Note: I don't actually need this third-party DLL file file for the installed application to run.

  <Binary Id="MyCustomAction.dll" SourceFile="MyCustomAction.CA.dll" />

  <CustomAction Id="FixupConfigForMysql" Return="check" />

  <InstallExecuteSequence>
     <Custom Action='FixupConfigForMysql' After='InstallFiles'>NOT Installed</Custom>
  </InstallExecuteSequence>

Do I need to install the third-party DLL file (MySql.Data.dll) in order to get the custom action to run?

Can I just add another Binary tag with the third-party DLL file?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/1591700/how-to-execute-a-wix-custom-action-dll-file-with-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!