如何将 msiexec 属性传递给 WiX C# 自定义操作? [英] How do I pass msiexec properties to a WiX C# custom action?
问题描述
我正在使用 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:
string environmentName = session.Property["ENVIRONMENT"];
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屋!