我正在尝试在WiX中使用我的第一个自定义操作,并且得到:
错误2896:执行动作CustomActionTest失败。
我正在使用Visual Studio 2010,WiX 3.5、64位Windows 7 Ultimate,.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>
从动作:
namespace JudgeEditionCA
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomActionOne( Session session )
{
return ActionResult.Success;
}
}
}
以及来自定制操作的配置文件:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="false">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
最后,我在WiX项目中使用了对自定义操作的项目引用。我不确定自己在做什么错。
我通过运行带有/ lvx选项的msi来获取详细的日志记录,从而弄清楚了。我还必须将动作移至InstallExecuteSequence部分以获取有意义的错误消息。当对CA的调用在PushButton中时,没有任何有意义的返回。
<InstallExecuteSequence>
<Custom Action='CustomActionTest' After='InstallFinalize' />
</InstallExecuteSequence>
System.BadImageFormatException:无法加载文件或程序集'JudgeEdition'或其依赖项之一。该程序集是由比当前加载的运行时新的运行时构建的,无法加载。
我将useLegacyV2RuntimeActivationPolicy属性更改为true。一切开始顺利。
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
这些链接帮助我快速入门:
作为KnightsArmy的推论,当CustomAction元素上的DllEntry属性错误时,也会引发此错误。就我而言,我有错别字,唯一可以从日志中得到的错误信息是臭名昭著的错误2896。
我得到了相同的错误代码,但根本原因是因为其中一个“自定义操作”方法引发了异常。如果您不编写try-catch并编写有意义的错误消息。 MSI日志只会告诉您错误#。
欢呼声