简体   繁体   English

在C#自定义操作中更改安装程序属性

[英]change installer properties in C# custom action

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

To access a WiX property, such as those set with the Property element, use the Session object's indexer. 要访问WiX属性,例如使用Property元素设置的属性,请使用Session对象的索引器。 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;
}

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. 同样,您可以通过将其值设置为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. 因此,如果某个属性包含应该隐藏的信息,那么最好先在WiX标记中声明它并将其隐藏属性设置为yes。

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

You can't. 你不能。 Only Win32 DLLs and VBScript Immediate actions have write access to installer properties. 只有Win32 DLL和VBScript 立即操作才具有对安装程序属性的写访问权限。 Any other custom action type can only receive properties through their command line or through CustomActionData. 任何其他自定义操作类型只能通过其命令行或通过CustomActionData接收属性。

Here is a tutorial for a C++ DLL custom action: http://www.codeproject.com/KB/install/msicustomaction.aspx 以下是C ++ DLL自定义操作的教程: http//www.codeproject.com/KB/install/msicustomaction.aspx

To get and set Windows Installer properties you can use MsiGetProperty() and MsiSetProperty() . 要获取和设置Windows Installer属性,可以使用MsiGetProperty()MsiSetProperty()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM