System.IO.FileInfo 在 WIX 自定义操作中使用时向路径添加意外字符串
System.IO.FileInfo adds unexpected string to path when used in WIX Custom Action
我有一个 WIX(V3.11.1) installer in which I'm creating an FileInfo 基于传递给自定义操作的值。
传递给自定义操作的值是正确的,session.CustomActionData["INSTALLFOLDER"]
returns 正确路径,即 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\
我的设置感觉是在猜测 CustomActionData
中 INSTALLFOLDER
的值实际上是 [INSTALLFOLDER]
的值。记录时,该语法将解析为其正确的值。这就是它看起来不错的原因。但是,FileInfo
实际得到的值是这样的:
FileInfo targetDir = new FileInfo("[INSTALLFOLDER]");
这当然是 "The file named "[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" />
我有一个 WIX(V3.11.1) installer in which I'm creating an FileInfo 基于传递给自定义操作的值。
传递给自定义操作的值是正确的,session.CustomActionData["INSTALLFOLDER"]
returns 正确路径,即 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\
我的设置感觉是在猜测 CustomActionData
中 INSTALLFOLDER
的值实际上是 [INSTALLFOLDER]
的值。记录时,该语法将解析为其正确的值。这就是它看起来不错的原因。但是,FileInfo
实际得到的值是这样的:
FileInfo targetDir = new FileInfo("[INSTALLFOLDER]");
这当然是 "The file named "[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" />