通过 WiX 使用的 C# 中的自定义操作失败并出现错误 1154 [英] Custom Action in C# used via WiX fails with error 1154

查看:16
本文介绍了通过 WiX 使用的 C# 中的自定义操作失败并出现错误 1154的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2010 中使用 WiX 3.5.1930,目标是 .NET Framework 3.5.(就其自定义操作模板而言,后来每周构建的 WiX 似乎非常糟糕,至少目前如此.1930 是最新的构建,它似乎使可构建的 C# CA 具有工作参考.)

I am using WiX 3.5.1930 in Visual Studio 2010, targeting the .NET Framework 3.5. (Later weekly builds of WiX seem to be very broken with respect to their custom action template, at least for now. 1930 is the most recent build that seems to make a buildable C# CA with working references.)

我有两个用 C# 编写的自定义操作程序集.其中一个工作正常.另一个失败并出现以下错误:

I have two custom action assemblies written in C#. One of them works fine. The other fails with the following error:

CustomActionnNameHere returned actual error code 1154 (note this may not be 100% accurate if translation happened inside sandbox)

我已经比较了 .csproj 文件和 .wixproj 文件,并且尽我所能判断差异是否合适(例如,包含的 .cs 文件列表).我已将非工作 .wxs 更改为调用工作自定义操作而不是非工作自定义操作,并且它按预期工作.

I have compared the .csproj files and .wixproj files, and as best I can tell the differences are appropriate (e. g. list of included .cs files). I have changed the non-working .wxs to call the working custom action instead of the non-working custom action and it works as epxected.

我还可以看看什么来让它工作?

What else can I look at to get this working?

完整地说,1154 指的是无效的 DLL - net helpmsg 将其(英文)翻译为运行此应用程序所需的库文件之一已损坏."

Just to be complete 1154 refers to an invalid DLL - net helpmsg translates it (in English) to "One of the library files needed to run this application is damaged."

第二次对 dll 运行 peverify(在安装程序运行时从 windowsinstaller 中获取了一个副本),它说 dll 中的一切都很好.DLL 仅具有返回成功"的自定义操作方法,因此没有太多需要验证的内容,但它确实确认 DLL 没有损坏.

Second edit: ran peverify against the dll (grabbed a copy out of windowsinstaller while the installer was running) and it says everything is fine in the dll. The DLL only has the custom action method with a "return success" so there's not a lot for it to verify, but it does confirm the DLL is not corrupt.

第三次损坏的自定义操作中的代码如下:

Third edit: The code in the broken custom action follows:

using Microsoft.Deployment.WindowsInstaller;

namespace Framework.Installer.Database {
    public class CustomActions {

        [CustomAction]
        public static ActionResult RunMigration(Session session) {

            return ActionResult.Success;
        }

    }
}

没什么大不了的..wxs的相关部分如下:

Not much to it. The relevant parts of the .wxs are as follows:

<InstallExecuteSequence>
  <Custom Action="DotNetMigratorCustomActionPreviousUp" After="SetMigrationPropertiesPreviousUp"><![CDATA[(&Database = 3)]]></Custom>
</InstallExecuteSequence>

<Binary Id="DotNetMigratorCustomActionDll"
        SourceFile="$(var.Framework.Installer.Database.CustomActions.TargetDir)SoftwareAnswers.Framework.Installer.Database.CustomActions.dll" />

<CustomAction Id="DotNetMigratorCustomActionPreviousUp"
              Return="check"
              BinaryKey="DotNetMigratorCustomActionDll"
              DllEntry="RunMigration"
              Execute="deferred" />

推荐答案

听起来你在使用 DTF.如果你看到:

It sounds like you are using DTF. If you see:

using Microsoft.Deployment.WindowsInstaller;

那你肯定是.请务必阅读以下内容以了解其工作原理:

then you certainly are. Be sure to read the following for how it all works:

部署工具基金会 (DTF) 托管自定义操作

您还可以在 WiX 下的开始菜单中找到 DTF 帮助 chm.

Also you'll find a DTF help chm in the start menu under WiX.

基本上,在我看来,您正在将 .NET 程序集连接到安装程序中,而不是未管理的包装器 dll.阅读上面的文章,了解如何在 Depends 中查看它并了解会发生什么.维克斯 |C# 自定义操作项目应输出 Foo.dll 和 Foo.CA.dll.您希望在安装程序中使用后者.

Basically it sounds like to me you are wiring the .NET assembly into the installer instead of the unmanged wrapper dll. Read the above article for an overview of how to look at it in Depends and to know what to expect. The WiX | C# Custom Action project should output Foo.dll and Foo.CA.dll. You want the later in your installer.

对于将来登陆此页面的人(答案最初是给海报的),有一个完整的清单要检查:

For people who land on this page in the future (the answer was originally for the poster ) there is a whole list of things to check:

  1. 您是否在二进制表中引用了正确的 DLL?
  2. 您是否引用了正确的导出函数名称?
  3. 你的课程是公开的吗?
  4. 您的方法是否使用了正确的签名?IE.是吗:
  5. 标有正确的 CustomAction 属性
  6. 标记为公开?
  7. 标记为静态?
  8. 返回 ActionResult?
  9. 以会话为论据?
  10. 确保您使用的是 WiX C# 自定义操作项目类型,以确保调用 postbuild 事件来创建本机 DLL 包装器.(见 #1)

其中任何一种都可能导致 1154 错误.这就是我写一篇关于这个主题的综合博客文章并在这个答案中链接到它的原因.重要的是要充分了解托管代码如何呈现给非托管 Windows Installer 服务,并了解如何使用 Depends 来验证公共静态方法是否作为标准调用函数导出到 WiX/DTF 生成的结果 .CA.dll 中.

Any one of these can cause an 1154 error. This is the reason I wrote a comprehensive blog article on the subject and linked to it in this answer. It's important to fully understand how managed code is presented to the unmanaged Windows Installer service and to know how to use Depends to validate that the public static method is exported as a stdcall function in the resulting .CA.dll that WiX/DTF produces.

这篇关于通过 WiX 使用的 C# 中的自定义操作失败并出现错误 1154的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆