【问题标题】:Wix CustomAction can't access written files with before InstallFinalizeWix CustomAction 无法在 InstallFinalize 之前访问写入的文件
【发布时间】:2020-03-26 21:45:51
【问题描述】:

我有一个应该安装我的 c# 应用程序的 Wix 项目。文件复制和防火墙例外已经在起作用。现在我想用自定义操作修改 json 配置文件。我想读取所有 json 文件,更改一些值并将它们写回程序文件。这是我的 CA 定义:

<CustomAction Id="PrepareConfigurationFilesCustomAction" BinaryKey="InstallerCA" DllEntry="PrepareConfigurationFilesCustomAction" Execute="immediate" Impersonate="no" Return="check" />
<CustomAction Id="CreateConfigurationFiles" BinaryKey="InstallerCA" DllEntry="CreateConfigurationFiles" Execute="deferred" Impersonate="no" Return="check" />
<Custom Action="PrepareConfigurationFilesCustomAction" Before="CreateConfigurationFiles">NOT Installed AND NOT REMOVE</Custom>
<Custom Action="CreateConfigurationFiles" Before="InstallFinalize">NOT Installed AND NOT REMOVE</Custom>

如果我打开 .msi wirth Orca,Actios 的顺序似乎是正确的。

enter image description here

InstallFiles                                                            4000
PrepareConfigurationFilesCustomAction   NOT Installed AND NOT REMOVE    6598
CreateConfigurationFiles                NOT Installed AND NOT REMOVE    6599

但是当我运行 .msi 时出现异常

Excetion TrownSystem.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Vendor\Product\etc\Configurations'.
   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 Vendor.Application.Product.Setup.Actions.CustomActionData.ConfigurationFilesCustomActionData.CreateSessionCustomActionData(Session session) in C:\work\\Projects\Installation\Packages\Product.Workstation\Setup.Actions\CustomActionData\ConfigurationFilesCustomActionData.cs:line 99

当我附加调试器时,我可以在代码和文件系统中看到文件不存在。

如果我将第一个 Ca (PrepareConfigurationFilesCustomAction) 更改为 Execute="deferred",则会写入文件但我无法访问会话值...

对我有什么想法或解决方案吗?

谢谢!

【问题讨论】:

    标签: c# wix windows-installer custom-action


    【解决方案1】:

    解决方案?:最好的解决方案是将 JSON 文件安装到只读位置,然后使用您的应用程序将它们复制到用户配置文件并更新它们根据您的需要。这并不总是可能的 - 例如当没有应用程序二进制文件可以启动时。

    拒绝访问:您不能以普通用户的身份写入程序文件下的位置。这是关于该问题的一篇文章:System.UnauthorizedAccessException while running .exe under program files

    技术:您看到的行为的原因是 InstallExecuteSequence 被处理了两次。首先在“即时模式”中运行即时模式自定义操作并构建一个事务脚本以供执行。当您到达 InstallFinalize 时,序列将从 InstallInitialize 再次运行,此时系统会通过文件安装、注册表更改等进行更新……此模式下的自定义操作将被推迟。他们不能直接访问属性。属性值必须通过称为 CustomActionData 的机制“发送”给它们。相当笨重。如果您使用该应用程序完成工作,则不需要?

    CustomActionData 概念之前已经被其他人很好地解释过,我只是链接到您可以在其他地方访问的信息:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-27
      • 2016-04-27
      • 2021-03-29
      • 2013-08-25
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多