【问题标题】:Wix: Passing a property back from a C# custom actionWix:从 C# 自定义操作传回属性
【发布时间】:2014-04-28 20:53:30
【问题描述】:

是否可以从 WiX 自定义操作传回属性?几个小时以来,我一直在试图找出解决方案,我已经看到了很多答案,但没有一个对我有用。这是我尝试过的,

C#(自定义操作)

public class CustomActions
{
    [CustomAction]
    public static ActionResult TestAction(Session session)
    {
        session["FOO"] = "BAR";
        return ActionResult.Success;
    }
}

WiX FooDlg.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <Property Id="FOO"/>
    <UI>
      <Dialog Id="FooDlg" Width="370" Height="270" Title="Foo">

        <Control Id="FOO" Type="Edit" Property="FOO" Height="17" Width="45" X="50" Y="150" Text="[FOO]" Indirect="no"/>

        <Control Id="FOO" Type="PushButton" X="150" Y="200" Width="56" Height="17" Text="Test FOO">
          <Publish Event="DoAction" Value="Testing">1</Publish>
        </Control>

      </Dialog>
    </UI>
    <CustomAction Id='FOO' BinaryKey='FooBinary' DllEntry='TestAction' Execute='immediate' Return='check'/>
    <Binary Id='FooBinary' SourceFile='FOO.dll'/>
  </Fragment>
</Wix>

【问题讨论】:

    标签: c# windows wix installation windows-installer


    【解决方案1】:

    是的,您可以从安装程序中的自定义操作传回属性。确保属性是公开的(名称中只有大写字母),并且您的自定义操作被安排为立即执行并在您的对应对话框加载之前执行(使用详细日志在安装程序执行期间跟踪属性值,只需搜索为其中的属性名称)。

    【讨论】:

    • 如果您打算在 InstallExecuteSequence 中使用它,您可能还需要将其标记为安全。
    【解决方案2】:

    您需要在 Publish 标签中指定您的 CustomAction 的 Id:

    <Publish Event="DoAction" Value="FOO">1</Publish>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多