【问题标题】:Wix Custom actions run dll c#Wix 自定义操作运行 dll c#
【发布时间】:2020-07-05 12:34:17
【问题描述】:

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

“此 Windows 安装程序包存在问题。无法运行完成此安装所需的 DLL。请联系您的支持...”

这就是我所做的:

       <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 个类和 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 项目的每个文件夹中..

谢谢!

【问题讨论】:

  • 现在没时间回答,但是除非您具有提升的权限,否则写入操作将失败 - 如果您将其插入 GUI 序列或安装序列过早或过晚,则不会出现这种情况.尝试显示一个消息框,以确保您有自定义操作的“心跳”。你能在 github.com 上找到很多项目吗?
  • 你能给我一个这样的项目的链接吗?我对此很陌生。谢谢

标签: c# visual-studio wix installation wix3


【解决方案1】:

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

如果您在 Visual Studio WiX / Votive 中正确执行此操作,则会使用 MakeSfxCA.exe 自动为您执行此编译。请参阅上面链接中的屏幕截图。

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

内联,本质。请注意 Binary 元素 行末尾的 ".CA.dll"

<..>

<!-- 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>

<..>

【讨论】:

  • 从上面你需要什么?我可以只添加一个顶部。只是 SourceFile 字符串吗?
【解决方案2】:

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

【讨论】:

  • 这是什么?我的 bin 文件夹中没有它
  • 听起来您没有使用 WiX 提供的项目模板或在构建后事件中调用 MakeSfxCA。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多