【发布时间】:2017-07-04 17:07:57
【问题描述】:
我需要:
- 从用户(从 UI)获取数据,并将该数据放入属性中
- 使用自定义操作将属性导入到某些 C# 代码中
- 对属性做一些事情(加密值),
- 将值返回导出到 WiX,我将在其中
- 创建一个注册表项并将加密的值放入其中
除了#4 之外,我可以完成该列表中的所有任务。也就是说,我似乎无法将 和 导出值导入 C# 代码。我认为问题出在时间上。
这是一个自定义操作的示例,用于将某些属性导入到某些 C# 代码中:
<Property Id="VALUE" Value="value"/>
<SetProperty Id="CustomAction_PassProperty"
Value="VALUE=[VALUE]"
Sequence="execute"
Before="CustomAction_PassProperty"/>
<Binary Id="Binary_PassProps"
SourceFile="$(var.CreateRegistryKey.TargetDir)CreateRegistryKey.CA.dll"/>
<!-- Note that 'Impersonate="no"' elevates the privilege of the C# code, needed to create keys -->
<CustomAction Id="CustomAction_PassProperty"
BinaryKey="Binary_PassProps"
DllEntry="CreateKeys"
Execute="deferred"
Impersonate="no"
Return="check"
HideTarget="yes"/>
<InstallExecuteSequence>
<Custom Action="CustomAction_PassProperty"
After="InstallInitialize"/>
</InstallExecuteSequence>
请注意,该操作是在 InstallInitialize 之后完成的。
接下来,如何在 C# 代码中获取导入的属性并将其转换为变量:
[CustomAction]
public static ActionResult CreateKeys(Session session)
{
string value = session.CustomActionData["VALUE"];
return ActionResult.Success;
}
接下来,这是一个如何将 C# 代码中的变量作为属性导出回 WiX 的示例:
<Binary Id="Binary_CustomActionTemplate"
SourceFile="$(var.CustomAction.TargetDir)CustomAction.CA.dll"/>
<CustomAction Id="CustomAction_CustomActionTemplate"
BinaryKey="Binary_CustomActionTemplate"
DllEntry="CustomActionTemplate"
Execute="immediate"
Return="check"/>
<InstallUISequence>
<Custom Action="CustomAction_CustomActionTemplate" After="LaunchConditions"/>
</InstallUISequence>
这一次动作是在LaunchConditions之后完成的。
最后,如何在 C# 中创建一个 Property,给它一个值,然后将它发送回 WiX:
[CustomAction]
public static ActionResult CreateKeys(Session session)
{
session["VALUE"] = "Hello, world.";
return ActionResult.Success;
}
我认为问题在于——即在安装过程中——我同时做两件事(导入和导出),但我不确定。也就是说,我需要将数据导入到 C# 代码中,在 C# 代码中做一些事情,然后 从 C# 代码中导出数据。 但是怎么做?!?(对着天空戏剧性地挥手)
总结一下:如何在WiX中将数据导入导出到C# Custom Action(使用相同的C#代码)?
【问题讨论】:
-
我在我的答案中添加了一个替代选项,以防您已经阅读它并且没有看到编辑。答案有点乱对不起=]
标签: c# wix custom-action