c# - System.IO.FileInfo 在 WIX 自定义操作中使用时将意外字符串添加到路径
问题描述
我有一个WIX(V3.11.1)安装程序,我在其中创建一个基于传递给自定义操作的值的FileInfo 。传递给自定义操作的值是正确的,session.CustomActionData["INSTALLFOLDER"]
返回正确的路径,即C:\Program Files(x86)\MyApplication
.
不幸的是,当我创建时FileInfo targetDir = new FileInfo(session.CustomActionData["INSTALLFOLDER"])
,结果targetDir.FullName
是C:\Windows\Installer\MSIE335.tmp-\C:\Program Files(x86)\MyApplication\
。
我试图找到有关FileInfo构造函数如何工作的任何信息,但没有任何结果。您有什么想法为什么会C:\Windows\Installer\MSIE335.tmp-\
出现在 FileInfo 中以及如何使用真实路径创建它?
我用来检查所有值的代码:
string path = session.CustomActionData["INSTALLFOLDER"];
session.Log(path); //result is C:\Program Files(x86)\MyApplication
FileInfo targetDir = new FileInfo(path);
session.Log(targetDir.FullName); // result is C:\Windows\Installer\MSIE335.tmp-\C:\Program Files(x86)\MyApplication\
解决方案
我的设置感觉猜测INSTALLFOLDER
你CustomActionData
的值实际上是值[INSTALLFOLDER]
。记录时,该语法将被解析为正确的值。这就是为什么它看起来不错。但是,FileInfo
实际得到的是一个值,例如:
FileInfo targetDir = new FileInfo("[INSTALLFOLDER]");
这当然是“当前目录中名为“[INSTALLFOLDER]”的文件”。这与您的第二个日志行相匹配。
解决方法是确保您传递CustomActionData 中的值。 INSTALLFOLDER
有几种不同的方法可以做到这一点,具体取决于您如何安排延迟的自定义操作和设置命名属性。例如,使用SetProperty
应该是修复它的简单方法。
更新:Hawex 提供了一个定义自定义操作的片段。它看起来像:
<Property Id="CustomActionOnInstall" Value="INSTALLFOLDER=[INSTALLFOLDER]" />
<CustomAction Id="CustomActionOnInstall" BinaryKey="CustomActions" Execute="deferred"
Impersonate="no" DllEntry="OnInstall" Return="check" />
<InstallExecuteSequence>
<Custom Action="CustomActionOnInstall" Before="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
要修复,只需将静态(未评估)更改Property
为SetProperty
:
<SetProperty Id="CustomActionOnInstall" Value="INSTALLFOLDER=[INSTALLFOLDER]"
Before="CustomActionOnInstall" Sequence="execute" />
推荐阅读
- amazon-web-services - 在 AWS EC2 中创建新密钥对时出错
- mysql - 获取特定时间范围的数据
- dns - F5 Big IP 打印未知 JS 消息
- reactjs - reactJS隐藏了一个在渲染中留下很多空白
- node.js - 在 Node/Express 应用程序中实现 Async/Await
- postgresql - 如何在 gitlab 中从内部 postgres db 迁移到外部 postgres db
- agda - cong 究竟如何才能正确输入?
- c# - 如何在子文件夹中组织 C# 源文件?
- python - 使用 Hough 变换检测深色线条和末端线条
- r - 在 R 中运行按列分组的多个回归