Wix 自定义操作 运行 dll c#

Wix Custom actions run dll c#

我正在使用自定义操作来 运行 来自 dll 的函数,但是当我 运行 我构建的 msi 时,我收到错误:

"There is a problem with this windows installer package. A DLL required for this install to complete could not be run. Contact you support..."

这就是我所做的:

       <Fragment>
<UI>
  <Dialog Id="UserRegistrationDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes">

    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next">
      <Publish Event="DoAction" Value="MyCustomAction">1</Publish>
      <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">CostingComplete = 1</Publish>
      <Publish Event="NewDialog" Value="SetupTypeDlg">ProductID</Publish>
    </Control>
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
    <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />
    <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes">
      <Text>Please enter your customer information</Text>
    </Control>
    <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
    <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes">
      <Text>{\WixUI_Font_Title}Customer Information</Text>
    </Control>
    <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />

  <Control Id="PlatformCombobox" Type="ComboBox" X="45" Y="127" Width="220" Height="18" ComboList="yes" Sorted="yes" Property="Platform">
    <ComboBox Property="Platform">
      <ListItem Value="1" Text="1"/>
      <ListItem Value="2" Text="2 "/>
      <ListItem Value="3" Text="3 "/>
      <ListItem Value="4" Text="4 "/>
    </ComboBox>
  </Control>
  </Dialog>
</UI>
    <Property Id="Platform" Value="2" />

    <CustomAction Id='MyCustomAction' BinaryKey='CreateFile' DllEntry='CreateFile'/>
    <Binary Id='CreateFile' SourceFile='SetupDll.dll'/>


  </Fragment>

如您所见,我正在尝试 运行 SetupDll.dll,其中包含 1 个 class 和 1 个函数:

using System.IO;
using Microsoft.Deployment.WindowsInstaller;

namespace SetupDll
{
    public class Creator
    {
        [CustomAction]
        public static ActionResult CreateFile(Session session)
        {
            File.WriteAllText(@"C:\a.txt", "123");
            return ActionResult.Success;
        }
    }
}

但是我不明白这个问题。我将生成的 SetupDll.dll 放在 wix 项目的每个文件夹中..

谢谢!

二进制元素应指向 SetupDll.CA.dll 而不是 SetupDll.dll。

MakeSfxCA.exeFileName.CA.dll dll本质上是.NET 托管代码 dll 和依赖项的捆绑包,它模拟真实的 dll,以便 MSI 可以将其作为自定义操作处理。它是使用名为 MakeSfxCA.exe - There are some details here 的文件制作的(另请参阅 [=48= 中的答案 2 ]).

如果您在 Visual Studio WiX 中做的正确,Votive 会使用 MakeSfxCA.exe 自动神奇地为您进行编译。请参阅上面 link 中的屏幕截图。

这里有一些如何使用托管代码的示例:

  • (推荐,请查收)
  • Debugging C# custom actions

内联,精华。请注意 ".CA.dll" 二进制元素 [=36] 行的末尾=]:

<..>

<!-- Point to custom action binary -->
<Binary Id="CustomActions" SourceFile="$(var.CustomAction1.TargetDir)$(var.CustomAction1.TargetName).CA.dll" />

<!-- Specify custom action name in above binary -->
<CustomAction Id="CA1" BinaryKey="CustomActions" DllEntry="CustomAction1"/>

<!-- Insert custom action in GUI sequence -->
<InstallUISequence>
  <Custom Action="CA1" After="CostFinalize" />
</InstallUISequence>

<!-- Insert custom action in install sequence -->
<InstallExecuteSequence>
  <Custom Action="CA1" After="CostFinalize" />
</InstallExecuteSequence>

<..>