简体   繁体   English

在WiX中安装期间创建临时文件夹

[英]Creating a temporary folder during installation in WiX

In WiX, how to create a temporary hidden folder (Like SUPPORTDIR In IS)on the target machine,during installation and how to add the files to it, that are stored in the Binary table, and then subsequently delete it after Installation is completed in wix? 在WiX中,如何在目标计算机上创建临时隐藏文件夹(如IS中的SUPPORTDIR),在安装过程中以及如何向其中添加文件,存储在二进制表中,然后在安装完成后立即删除它威克斯?

Grateful to any help. 感谢任何帮助。

Thanks. 谢谢。

This is a sample solution that extends the idea I referenced in my own comment. 这是一个示例解决方案,扩展我在自己的评论中引用的想法

To tell it short, you don't have to complicate the solution by adding extra files to the binary table, extract them in a custom action and remove afterwards. 简而言之,您不必通过向二进制表添加额外文件来使解决方案复杂化,在自定义操作中提取它们并在之后删除。 The built-in mechanism on DTF custom actions does it for you. DTF自定义操作的内置机制可以为您完成。

Let's say you have an XML file you'd like to read in the custom action to output some info to the installation log file. 假设您有一个XML文件,您希望在自定义操作中读取该文件以将某些信息输出到安装日志文件。 First of all, you should create a Custom Action project in VS (File -> New -> Project... and choose "C# Custom Action project" template). 首先,您应该在VS中创建一个自定义操作项目(文件 - >新建 - >项目...并选择“C#自定义操作项目”模板)。

Then, add an XML file as a content: right-click the project in the Solution Explorer, choose Add -> New Item... and select XML file. 然后,添加XML文件作为内容:在解决方案资源管理器中右键单击项目,选择添加 - >新项...并选择XML文件。 Let's call it data.xml . 我们称之为data.xml The contents might look like this: 内容可能如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<settings>
  <setting name="a" value="one" />
  <setting name="b" value="two" />
</settings>

Next, add some code to read the values from this XML and write something to the installation log (remember, it's just a sample): 接下来,添加一些代码来读取此XML中的值并将某些内容写入安装日志(请记住,它只是一个示例):

[CustomAction]
public static ActionResult ReadXml(Session session)
{
  var doc = XDocument.Load("data.xml");
  var settings = from setting in doc.Descendants("setting")
                 select new
                 {
                   Name = setting.Attribute("name").Value,
                   Value = setting.Attribute("value").Value
                 };

  foreach (var setting in settings)
  {
    session.Log(string.Format("{0} = {1}", setting.Name, setting.Value));
  }

  return ActionResult.Success;
}

Note that I reference the XML file as just data.xml - when custom action runs, it will find the file in the same directory it runs from. 请注意,我将XML文件仅作为data.xml引用 - 当自定义操作运行时,它将在运行它的同一目录中找到该文件。

Finally, add your custom action to the installation process: 最后,将自定义操作添加到安装过程:

<Binary Id="MainBinary" SourceFile="bin\ExtraFiles.CA.dll" />
<CustomAction Id="ReadXmlCA" BinaryKey="MainBinary" DllEntry="ReadXml" Execute="deferred" />

<InstallExecuteSequence>
  <Custom Action="ReadXmlCA" After="InstallFiles" />
</InstallExecuteSequence>

Now, build the MSI package and run the installation the following way: 现在,构建MSI包并按以下方式运行安装:

msiexec -i SupportDir.msi /l*v install.log

When the package installation completes, open the install.log file and search for CustomActions.ReadXml . 程序包安装完成后,打开install.log文件并搜索CustomActions.ReadXml You'll see something like this: 你会看到这样的事情:

SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSIAB8D.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action ExtraFiles!ExtraFiles.CustomActions.ReadXml
a = one
b = two

Obviously, custom action has done its job: it read the XML file contents and output proper info to the log file. 显然,自定义操作已完成其工作:它读取XML文件内容并将正确的信息输出到日志文件。 One more thing to note: the temp directory path. 还有一点需要注意:临时目录路径。 Try to navigate to that directory - you'll find out that it is empty. 尝试导航到该目录 - 你会发现它是空的。

This means DTF took care about extracting files to the proper location to make it available for the custom action code, and cleaning up after the job is done. 这意味着DTF负责将文件提取到适当的位置,以使其可用于自定义操作代码,并在作业完成后进行清理。

Hope this overview helps understanding the way it works. 希望此概述有助于理解其工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在安装wix安装程序的过程中如何复制folder / files1..to..files5 - How to copy folder/files1..to..files5 during the installation of wix installer Wix在安装文件夹中添加外部dll - Wix add external dll in the installation folder 在WIX中使用环境变量创建文件夹的快捷方式 - Creating shortcut to folder in WIX that uses environmental variable Wix CustomAction [C#]会话。安装过程中不显示消息 - Wix CustomAction [C#] session.Message is not show during the installation 如何使用 Wix# 将构建文件夹的所有内容添加到安装中? - How to add all contents of build folder to installation using Wix#? 某些文件第一次没有使用WIX复制到安装文件夹中 - Some files not copying in installation folder the first time using WIX wix 3.5 选择文件夹时记住公司名称 - wix 3.5 Remember Company name during folder selection wix:如何防止用户在应用程序的安装或升级过程中重新启动计算机 - wix: How to prevent user from restarting machine during the installation or upgrading of application 如何在命令行安装过程中使用作为参数传递的值从wix自定义操作更新appsettings.json? - How to update appsettings.json from wix custom actions with the values passed as parameter during command line installation? WIX非管理员安装 - WIX non admin Installation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM