msiexec不会将参数传递给自定义操作 [英] msiexec does not pass parameters to custom action

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

问题描述

我在MSI安装程序中有一个自定义操作,该操作对某些配置文件进行了一些更改。我的要求是在静默模式下运行安装,因此我正在使用msiexec。
这是命令:

I have a custom action inside an MSI installer that makes some changes to some configuration file. my requirement is to run the installation in silent mode so I am using msiexec. Here is the command:

msiexec /i myInstaller.msi /l* out.txt myContextParameter=value1

myContextParameter 永远不会传递给自定义操作,因此当我做了
context.Parameters [ myContextParameter] 我得到了 null 值。

myContextParameter is never passed to the custom action so when I do context.Parameters["myContextParameter"] I get a null value.

当我在UI模式下运行MSI时,参数正确传递。我还确保在 CustomActionData 中正确设置了属性的名称。

When I run my MSI in UI mode the parameter is passed correctly. I also made sure the name of the property is correctly set in the CustomActionData.

推荐答案

我一直在这上面撞墙,所以我发现了以下内容:

I've been beating my head against the wall on this one, so here's what I found out:

您必须在命令行上设置参数,以及每个自定义操作的 CustomActionData属性(无论您在安装,提交等下拥有什么)

You have to set your parameters on the commandline, as well as on the "CustomActionData" property on each of your Custom Actions (whatever you have under Install, Commit, etc)

您的命令行看起来像这样:

Your commandline will look something like this:

msiexec / i myInstaller.msi MYFIRSTPARAM = VALUE1 MYSECONDPARAM = VALUE2

然后,您的CustomActionData应该如下所示:

Then, your CustomActionData should look like this:

/ myfirstparam = [MYFIRSTPARAM] / mysecondparam = [MYSECONDPARAM]

现在,这是一堆特殊情况:

Now, here's a bunch of special cases:


  • 看起来@Klaus是正确的,您需要在参数名称中使用ALLCAPS。

  • It looks like @Klaus is right, you need to use ALLCAPS in your parameter names.

如果您的值包含空格,则在命令行和CustomActionData属性中都需要用引号引起来,例如:

if your values contain spaces, you'll need quotes around them in both the commandline and your CustomActionData properties, as in:

msiexec / i myInstaller.msi MYFIRSTPARAM = VALUE1 MYSECONDPARAM = VALUE2

/ myfirstparam = [MYFIRSTPARAM] / mysecondparam = [MYSECONDPARAM]

如果您的值以斜杠结尾,就像大多数文件路径一样,您会遇到一个奇怪的问题:当msiexec构建您的customactiondata时,它将创建此字符串:

if your values end with a slash, like most file paths do, you'll have a weird problem: when the msiexec builds your customactiondata, it'll create this string:

/ myfirstparam = C:\myfile\ / mysecondparam = C:\myfile\

在命令行中是否使用引号无关紧要,如果该斜杠是值的最后一个字符,则将其有效地读取为转义字符,并在您的customactiondata属性中转义引号。这会造成破坏。解决方案是:1)在参数和最后一个引号之间添加一个空格,然后记住在代码中的某个位置trim(),或2)在参数和引号之间添加和额外的斜杠,以避开转义字符。参见下面的两种方法:

it doesn't matter if you use quotes on the commandline or not, if that slash is the last character on your value, it will effectively be read as an escape character, and will escape the quote in your customactiondata property. This causes havoc. The solution is to either 1) add a space between your parameter and the last quote, and then remember to trim() it in your code somewhere, or 2) add and extra slash between your parameter and quote, in order to escape the escape character. See both methods below:

/ myfirstparam = [MYFIRSTPARAM] / mysecondparam = [MYSECONDPARAM] \

希望有帮助。

这篇关于msiexec不会将参数传递给自定义操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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