如何将msiexec属性传递给WiX C#自定义操作? [英] How do I pass msiexec properties to a WiX C# custom action?

查看:88
本文介绍了如何将msiexec属性传递给WiX C#自定义操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Wxs 3.0创建的MSI文件。我的MSI引用了一个C#自定义操作,该操作使用新的 C#自定义操作项目

I have an MSI file being created with Wxs 3.0. My MSI references a C# custom action, written using the new C# Custom Action project.

我想将传递给我的自定义操作的参数传递给msiexec-例如:

I want to pass an argument to msiexec that gets routed to my custom action - for example:

msiexec / i MyApp.msi ENVIRONMENT = TEST#

msiexec /i MyApp.msi ENVIRONMENT=TEST#

在.wxs文件中,我指的是自定义操作,例如

In my .wxs file, I refer to my custom action like this:

<Property Id="ENVIRONMENT"/>
<Binary Id="WixCustomAction.dll"  SourceFile="$(var.WixCustomAction.Path)" />
<CustomAction Id="WixCustomAction" BinaryKey="WixCustomAction.dll"    DllEntry="ConfigureSettings"/>
<InstallExecuteSequence>
   <Custom Action="WixCustomAction" After="InstallFiles"></Custom>
</InstallExecuteSequence>

我的C#自定义操作设置如下:

My C# custom action is set up like this:

[CustomAction]
public static ActionResult ConfigureSettings(Session session)
{

}

我希望能够像这样访问属性:

I was expecting to be able to access the property like this:

字符串环境名称= session.Property [环境];

string environmentName = session.Property["ENVIRONMENT"];

但这似乎不起作用。

如何访问在自定义操作中传递给msiexec的属性?

How do I access the property I passed to msiexec in my custom action?

推荐答案

如果不是

<CustomAction Id="SetCustomActionDataValue"
              Return="check"
              Property="Itp.Configurator.WixCustomAction"
              Value="[ENVIRONMENT],G2,[CONFIGFILE],[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" />

您这样写:

<CustomAction Id="SetCustomActionDataValue"
              Return="check"
              Property="Itp.Configurator.WixCustomAction"
              Value="Environment=[ENVIRONMENT];G=G2;ConfigFile=[CONFIGFILE];TargetDir=[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" />

然后您将能够像这样引用变量:

then you will be able to reference your variables like this:

string env=session.CustomActionData["Environment"];

这篇关于如何将msiexec属性传递给WiX C#自定义操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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