使用WiX C#/ .NET 4自定义操作时出现错误2896

Kni*_*rmy 12 c# custom-action wix wix3.5

我想在WiX中使用我的第一个自定义操作,我得到:

错误2896:执行操作CustomActionTest失败.

我使用的是Visual Studio 2010,WiX 3.5,64位Windows 7旗舰版,.NET Framework 4.

以下是我认为的相关部分:

<Binary Id="JudgeEditionCA" SourceFile="..\JudgeEditionCA\bin\Debug\JudgeEdition.CA.dll" />
<CustomAction Id="CustomActionTest" BinaryKey="JudgeEditionCA" DllEntry="CustomActionOne" Execute="immediate"/>

<Control Id="Next" Type="PushButton" X="248" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" >
    <Publish Event="DoAction" Value="CustomActionTest">1</Publish>
    <Publish Event="DoAction" Value="InvalidClientDesc">CLIENT_DESC_VALID = "0"</Publish>
    <Publish Event="NewDialog" Value="VerifyReadyDlg">CLIENT_DESC_VALID = "1"</Publish>
</Control>
Run Code Online (Sandbox Code Playgroud)

从行动:

namespace JudgeEditionCA
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomActionOne( Session session )
        {
            return ActionResult.Success;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

以及自定义操作的配置文件:

<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="false">
        <supportedRuntime version="v4.0" />
    </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

最后,我在我的WiX项目中使用了项目引用来自定义操作.我不确定我做错了什么.

Kni*_*rmy 17

我通过使用/ lvx选项运行我的msi以获得详细的日志记录来解决这个问题.我还必须将我的操作移动到InstallExecuteSequence部分以获取有意义的错误消息.当对Win的调用是在PushButton中时,没有返回任何有意义的内容.

<InstallExecuteSequence>
    <Custom Action='CustomActionTest' After='InstallFinalize' />
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)

System.BadImageFormatException:无法加载文件或程序集"JudgeEdition"或其依赖项之一.此程序集由比当前加载的运行时更新的运行时构建,无法加载.

我将useLegacyV2RuntimeActivationPolicy属性更改为true.一切都开始很好地运作了.

<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" />
    </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这些链接帮助我加快了速度:

  • @Magnus,此文件包含在自定义操作程序集中,并且必须命名为CustomAction.config (6认同)
  • 你能解释一下这个<configuration>条目的位置吗?如果我理解正确,这通常是你放在app.config文件中的东西?CA通常是一个DLL程序集,所以这个信息在哪里? (2认同)