代码之家  ›  专栏  ›  技术社区  ›  MikeBaz - MSFT

通过WiX使用的C#中的自定义操作失败,出现错误1154

  •  17
  • MikeBaz - MSFT  · 技术社区  · 15 年前

    我有两个用C#编写的自定义操作程序集。其中一个很好用。另一个失败,错误如下:

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

    我还能看些什么来让它工作呢?

    编辑:只是为了完成1154引用了一个无效的DLL-net helpmsg将其(英文)翻译为“运行此应用程序所需的库文件之一已损坏。”

    第二次编辑:对dll运行peverify(在安装程序运行时从\windows\installer中获取了一个副本),它表示dll中的一切正常。DLL只有带有“return success”的自定义操作方法,因此没有太多需要验证的内容,但它确实确认了DLL没有损坏。

    第三次编辑:断开的自定义操作中的代码如下:

    using Microsoft.Deployment.WindowsInstaller;
    
    namespace Framework.Installer.Database {
        public class CustomActions {
    
            [CustomAction]
            public static ActionResult RunMigration(Session session) {
    
                return ActionResult.Success;
            }
    
        }
    }
    

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

    <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" />
    
    7 回复  |  直到 11 年前
        1
  •  54
  •   Christopher Painter    11 年前

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

    using Microsoft.Deployment.WindowsInstaller;
    

    Deployment Tools Foundation (DTF) Managed Custom Actions

    此外,您还可以在WiX下的“开始”菜单中找到DTF help chm。

    基本上,在我看来,您是在将.NET程序集连接到安装程序中,而不是连接到未整理的包装器dll中。阅读上面的文章,了解如何在dependens中看待它,并知道应该期待什么。WiX | C#Custom Action项目应该输出Foo.dll以及Foo.CA.dll. 你想在你的安装程序后面。

    1. 您是否在二进制表中引用正确的DLL?
    2. 你的课是公开的吗?
    3. 您的方法是否使用了正确的签名?即是:
    4. 标记为公共?
    5. 标记为静态?
    6. 返回ActionResult?
    7. 以会话作为论据?
    8. 确保您使用的是WiX C#Custom Action项目类型,以确保调用postbuild事件来创建本机DLL包装器。(见#1)

        2
  •  6
  •   sfradel    15 年前

    如果在visualstudio(voive)中创建自定义操作,请确保创建了Wix Custon操作项目而不是类库,否则必须使用MakeSfxCA工具来打包自定义操作。

        3
  •  6
  •   Juan C. Becerra    14 年前

    我刚发现同样的问题( )对我来说,这是因为我没有使用静态方法。我有这个:

    public ActionResult MyMethod(Session session)
    

    public static ActionResult MyMethod(Session session)
    

    改变方法后,效果很好。

    希望它能帮助别人。

        4
  •  4
  •   Elmar Pohl    12 年前

        5
  •  2
  •   rusty    12 年前

    我看到这个错误的另一个原因是我忘了将[CustomAction]属性添加到我的c#函数的名称中。

        6
  •  1
  •   Mug Developer    12 年前

    在我的例子中是函数名长度。这是27个字符,我们得到的错误。 我们将函数名改为24个字符,结果成功了。

        7
  •  0
  •   KnightsArmy    15 年前

    试着加入你的定制行动号召

    <InstallExecuteSequence/>
    

    希望得到更好的错误信息。根据操作的调用方式,我收到了不同的错误消息。另外,尝试使用fuslogvw.exe文件. 它可能会给你一个很好的错误信息。

        8
  •  0
  •   halfer    5 年前

    [CustomAction]

    我的代码看起来像

    namespace VerifyUserInfo {
        public class CustomActions {
    
            [CustomAction]
            public static ActionResult TryToLogin(Session session) {
    
                return ActionResult.Success;
            }
    
            public static ActionResult RegisterDevice(Session session) {
    
                return ActionResult.Success;
            }
    
        }
    }
    

    但后来我和 [自定义操作] 在新功能的正上方添加并解决了问题

    namespace VerifyUserInfo {
        public class CustomActions {
    
            [CustomAction]
            public static ActionResult TryToLogin(Session session) {
    
                return ActionResult.Success;
            }
    
            [CustomAction]
            public static ActionResult RegisterDevice(Session session) {
    
                return ActionResult.Success;
            }
    
        }
    }