我使用此代码(在“产品”节点中定义)来启动简单的自定义操作
<!-- Run as admin -->
<Property Id="Privileged" Value="1" />
<!-- .NET Framework must be 4.6-->
<PropertyRef Id="WIX_IS_NETFRAMEWORK_46_OR_LATER_INSTALLED" />
<Condition Message="You must install Microsoft .NET Framework 4.6 or higher.">
<![CDATA[Installed OR WIX_IS_NETFRAMEWORK_46_OR_LATER_INSTALLED]]>
</Condition>
<Binary Id="Ctav8.CustomAction.CA.dll"
SourceFile="$(var.Ctav8.CustomAction.TargetDir)Ctav8.CustomAction.CA.dll" />
<CustomAction Id="CustomAction1"
Return="check"
Execute="immediate"
BinaryKey="Ctav8.CustomAction.CA.dll"
DllEntry="CustomAction1" />
<InstallExecuteSequence>
<Custom Action="CustomAction1" After="InstallFiles" />
</InstallExecuteSequence>
这是一个简单的自定义操作及其配置
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Message(InstallMessage.Warning, new Record
{
FormatString = "test"
});
return ActionResult.Success;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
注意:配置文件名为“CustomAction.config”,其Build Action设置为“Content”。我试图将'useLegacyV2RuntimeActivationPolicy'设置为true和false,但结果仍然相同。
如果我将自定义操作项目的.NET Framework更改为3.5,则此代码可以正常工作。
怎么了?
由于
答案 0 :(得分:0)
我的CustomAction配置看起来像这样
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>
</startup>
它适用于目标.Net 4.5。也许你只需要翻转supportedRuntime标签。
答案 1 :(得分:0)
我解决了使用
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
这适用于.NET Framework 4.6.1