msiexec 不将参数传递给自定义操作

发布于 2024-08-20 08:00:51 字数 397 浏览 2 评论 0原文

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

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

myContextParameter 永远不会传递给自定义操作,所以当我这样做时 context.Parameters["myContextParameter"] 我得到一个 null 值。

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

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 is never passed to the custom action so when I do
context.Parameters["myContextParameter"] I get a null value.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

许仙没带伞 2024-08-27 08:00:51

我一直在这个问题上绞尽脑汁,所以这就是我发现的:

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

您的命令行将如下所示:

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

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

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


现在,这里有一些特殊情况:

  • 看起来 @Klaus 是对的,您需要在参数名称中使用全部大写。

  • 如果您的值包含空格,则在命令行和 CustomActionData 属性中都需要将它们括起来,如下所示:

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

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

  • 如果您的值以斜杠结尾(就像大多数文件路径一样),您将遇到一个奇怪的问题:当 msiexec 构建您的自定义操作数据时,它将创建以下字符串:

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

    无论您是否在命令行上使用引号,如果该斜杠是您的值的最后一个字符,它将有效地被读取为转义字符,并将转义您的 customactiondata 属性中的引号。这会造成严重破坏。解决方案是 1)在参数和最后一个引号之间添加一个空格,然后记住在代码中的某处修剪()它,或者 2)在参数和引号之间添加额外的斜杠,以逃避转义特点。请参阅下面的两种方法:

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

希望有所帮助。

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

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

Then, your CustomActionData should look like this:

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


Now, here's a bunch of special cases:

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

  • 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]"

  • 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\"

    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]\"

Hope that helps.

尘曦 2024-08-27 08:00:51

MixedCase 属性是“私有”的,不会从命令行传入。

ALLCAPS 属性是“公共”的,可以在命令行上传递。

然而,只有安全公共属性被传递到“服务器”(即在UAC提升期间保留)。请参阅 SecureCustomProperties 属性文档。

假设您尝试在延迟 CA 中访问此属性,这种情况发生在服务器端,因此您需要使用也标记为安全的公共属性(全部大写)。

这是使用 WiX 的示例:

<Property Id="MYPUBLICPROPERTY" Secure="yes" Value="{}">

MixedCase properties are "private" and will not be passed in from the command line.

ALLCAPS properties are "public" and can be passed in on the command line.

However only secure public properties are passed through to the 'server' (i.e. retained during UAC elevation). See the SecureCustomProperties property documentation.

Assuming you're trying to access this property in a deferred CA, this is happening on the server side so you need to use a public property (all caps) that is also marked as secure.

Here's an example using WiX:

<Property Id="MYPUBLICPROPERTY" Secure="yes" Value="{}">
灯角 2024-08-27 08:00:51

如果您希望能够从外部传递参数,则需要在参数名称中使用全部大写字母。我知道这听起来很奇怪,但是尝试一下! :-)

If you want to be able to pass parameters from the outside you need to use ALLCAPS in your parameter names. I know it sounds weird, but try it! :-)

手心的海 2024-08-27 08:00:51

我知道这是一个旧线程,但我在这里尝试了多种方法,似乎我不知所措。然后我在msdn上找到了以下线程:

http://social.msdn.microsoft.com/Forums/windows/en-US/ 8dd009ce-52d5-4737-98c8-89d9831ab60b/unable-to-pass-parameters-to-msi-thro-msiexec-via-command-prompt?forum=winformssetup&prof=required

在 ORCA 中查看 MSI,您可以在“CustomAction”下看到一些条目。这些条目基本上会覆盖从命令提示符传入的值。如果您只是删除 CustomAction 表中的条目,例如:“CustomTextA_SetProperty_EDIT1”,然后保存 MSI(另存为在 ORCA 中具有不同的行为)。然后,您可以将属性值从命令行传递到 MSI。这将允许我使用 msiexec 远程安装,现在我可以通过命令行将参数传递给安装。我想发生这种情况是因为 CustomAction 值的逻辑是在从命令行填充属性值后执行的,这意味着 CustomAction 值会覆盖命令行填充的值。

线程底部还有一个链接,可以在 VS 中(而不是 ORCA)进行一些操作。

http://blogs.technet.com/b/alipka/archive/2007/04/20/how-to-use-custom-actions-in-visual-studio -setup-project-msi-from-command-line.aspx

I know this is an old thread, but I tried a variety of things here and it seemed that I was at a loss. I then found the following thread on msdn:

http://social.msdn.microsoft.com/Forums/windows/en-US/8dd009ce-52d5-4737-98c8-89d9831ab60b/unable-to-pass-parameters-to-msi-thro-msiexec-via-command-prompt?forum=winformssetup&prof=required

Viewing the MSI in ORCA, you can see a few entries under "CustomAction." These Entries will basically override the values passed in from the command prompt. If you simply delete the entries in the CustomAction Table like: "CustomTextA_SetProperty_EDIT1" and then save the MSI (Save AS has a different behavior in ORCA). You can then pass the Property Values from the command line to the MSI. This will allow me to install remotely using msiexec and I am now be able to pass the parameters to the install via the command line. I imagine this happens because the logic for the CustomAction values is executed after having populated the property values from the command line which means that the CustomAction values overwrite the command line populated values.

There is also a link at the bottom of the thread to do some manipulation in VS as opposed to ORCA.

http://blogs.technet.com/b/alipka/archive/2007/04/20/how-to-use-custom-actions-in-visual-studio-setup-project-msi-from-command-line.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文