【发布时间】:2021-08-27 05:35:21
【问题描述】:
我正在尝试在自定义操作中编辑已安装的 cmd 文件:
<CustomAction
Id="CA_EditScriptAction"
Return="check"
Execute="deferred"
Impersonate="no"
BinaryKey="CustomActions"
DllEntry="EditScriptAction"
/>
它在PublishProduct 操作之后调用。
问题是,我找不到该文件,因为由于某种原因,当它使用诸如Directory.GetFiles(ABSOLUTE_PATH) 之类的方法时,它会在绝对路径之前添加临时安装程序目录的路径。以下是日志:
SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI941A.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action MSIActions!MSIActions.CustomActions.EditScriptAction
CUSTOM_DEBUG: C:\Program Files\SomeApp\
ERROR in EditScriptAction: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\Installer\MSI941A.tmp-\C:\Program Files\SomeApp\'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.GetFiles(String path)
at MSIActions.CustomActions.EditScriptAction(Session session) in D:\Projects\Visual Studio\app\MSIActions\CustomAction.cs:line 57
CustomAction CA_EditScriptAction returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
正如我在日志中看到的,它将操作提取到 C:\Windows\Installer\MSI941A.tmp-\ 文件夹中,而不是 C# 方法将该文件夹添加到我传递给函数的任何路径中,如下所示:
ERROR in EditScriptAction: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\Installer\MSI941A.tmp-\C:\Program Files\SomeApp\'.
而我经过的路径是C:\Program Files\SomeApp\。
这是发生的代码:
[CustomAction]
public static ActionResult EditWebsharkScriptAction(Session session)
{
CustomActionData data = session.CustomActionData;
var install_dir = data["INSTALLFOLDER"];
session.Log("CUSTOM_DEBUG: " + install_dir);
var files = Directory.GetFiles(install_dir); //Exception is thrown here
//the rest of the code
}
如何防止 C# 将临时路径作为原始路径的前缀?
编辑: 正如我所观察到的,这只发生在非常量变量上。如果我使用硬编码路径创建一个 const 变量,C# 不会预先添加该临时文件夹路径...
【问题讨论】:
标签: c# wix windows-installer wix3