在C#自定义操作中更改安装程序属性 [英] change installer properties in C# custom action

查看:101
本文介绍了在C#自定义操作中更改安装程序属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的C#自定义操作中更改安装程序属性?

How to change installer properties in my C# custom action?

推荐答案

要访问WiX属性,例如使用属性元素,请使用
会话对象的索引器。下面是一个示例:

To access a WiX property, such as those set with the Property element, use the Session object's indexer. Here is an example:

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
string myProperty = session["MY_PROPERTY"];
return ActionResult.Success;
}

设置属性同样简单。您可以通过使用属性的
名称引用键来设置值。下面是一个示例:

Setting properties is just as easy. You'll set the value by referencing the key with the name of your property. Here's an example:

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session["MY_PROPERTY"] = "abc";
return ActionResult.Success;
}

如果在设置属性时不存在该属性,则会创建该属性。同样,可以通过将属性的值设置为null来
清除属性。通过自定义操作创建或更改属性值
不会阻止安装程序在安装日志
中显示这些属性。因此,如果属性包含应隐藏的信息,则最好先在WiX标记中声明该属性,并将其隐藏属性
设置为yes,这样,您的收入会提高

If the property doesn't exist when you set it, it will be created. Similarly, you can clear a property by setting its value to null. Creating or changing property values from a custom action doesn't stop the installer from displaying those properties in the install log. So, if a property holds information that ought to be hidden, you're better off declaring it in your WiX markup first and setting its Hidden attribute to yes.

<Property Id="MY_PROPERTY" Hidden="yes" />

这篇关于在C#自定义操作中更改安装程序属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆