WiX 自定义操作与 DTF...很困惑
好吧,我决定用 WiX 做我想做的事情的唯一方法(感谢我没有写的旧安装程序,我现在必须升级)是使用一些自定义操作。
基本上,我需要在删除现有产品之前备份文件,并在删除现有产品之后再次恢复该文件。我认为这就是所谓的“类型 2 自定义操作”。
我认为我理解的顺序,但是,我不理解的首先是如何将数据传递到我的 C# 操作(文件位于 WiX 中的目录)以及如何引用我的 C#(DTF?)操作Binary 和 CustomAction 标签。
另外,所有这些都需要在标签中吗?所有的例子都表明了这一点。
这是我到目前为止在 .WXS 文件中的内容...
<Binary Id="backupSettingsAction.dll"
SourceFile="backupSettingsAction.CA.dll"/>
<CustomAction
Id="BackupSettingsAction"
BinaryKey="backupSettingsAction.dll"
DllEntry="CustomAction"
Execute="immediate" />
<InstallExecuteSequence>
<Custom Action="backupSettingsAction.dll" Before="InstallInitialize"/>
<RemoveExistingProducts After="InstallFinalize" />
<Custom Action="restoreSettingsAction.dll" After="RemoveExistingFiles"/>
</InstallExecuteSequence>
我需要备份的文件是以前安装的设置文件(需要保持完整),它位于目录中:
<Directory Id="CommonAppDataFolder" Name="CommonAppData">
<Directory Id="CommonAppDataPathways" Name="Pathways" />
</Directory>
甚至有一个组件标签,尽管我需要备份已经存在的文件:
<Component Id="Settings" Guid="A3513208-4F12-4496-B609-197812B4A953" NeverOverwrite="yes" >
<File Id="settingsXml" ShortName="SETTINGS.XML" Name="Settings.xml" DiskId="1" Source="\\fileserver\Release\Pathways\Dependencies\Settings\settings.xml" Vital="yes" />
</Component>
这是引用 Visual Studio (2005) 为我创建的 C# 文件:
namespace backupSettingsAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("backing up settings file");
//do I hardcode the directory and name of the file in here, or can I pass them in?
return ActionResult.Success;
}
}
}
非常感谢任何帮助。谢谢你!
Okay, I have decided the only way I can do what I want to do with WiX (thanks to an old installer I didn't write that I now have to upgrade) is with some CUSTOM ACTIONS.
Basically, I need to back up a file before the RemoveExistingProducts and restore that file again after RemoveExistingProducts. I think this is what's called a "type 2 custom action."
The sequencing I think I understand, however, what I don't understand is first of all how I pass data to my C# action (the directory the file is in from the WiX) and how to reference my C# (DTF?) action with the Binary and CustomAction tags.
Also, does all this need to be in a tag? All the examples show it that way.
Here is what I have so far in the .WXS file...
<Binary Id="backupSettingsAction.dll"
SourceFile="backupSettingsAction.CA.dll"/>
<CustomAction
Id="BackupSettingsAction"
BinaryKey="backupSettingsAction.dll"
DllEntry="CustomAction"
Execute="immediate" />
<InstallExecuteSequence>
<Custom Action="backupSettingsAction.dll" Before="InstallInitialize"/>
<RemoveExistingProducts After="InstallFinalize" />
<Custom Action="restoreSettingsAction.dll" After="RemoveExistingFiles"/>
</InstallExecuteSequence>
The file I need to back up is a settings file from the previous install (which needs to remain intact), it is located in the directory:
<Directory Id="CommonAppDataFolder" Name="CommonAppData">
<Directory Id="CommonAppDataPathways" Name="Pathways" />
</Directory>
And even has a Component tag for it, though I need to back the file up that exists already:
<Component Id="Settings" Guid="A3513208-4F12-4496-B609-197812B4A953" NeverOverwrite="yes" >
<File Id="settingsXml" ShortName="SETTINGS.XML" Name="Settings.xml" DiskId="1" Source="\\fileserver\Release\Pathways\Dependencies\Settings\settings.xml" Vital="yes" />
</Component>
And this is referencing the C# file that Visual Studio (2005) created for me:
namespace backupSettingsAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("backing up settings file");
//do I hardcode the directory and name of the file in here, or can I pass them in?
return ActionResult.Success;
}
}
}
Any help is greatly apprecaited. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以回到为什么您认为您需要自定义操作吗?
根据您试图解决的问题,您应该能够执行以下两件事之一:
1) 将 XML 文件放入其自己的组件中,标记为密钥文件并设置为永久。
2) 创建一个虚拟 DLL 并为其指定版本 1.0.0.0。以后切勿增加此 DLL 的版本号。将 DLL 和 XML 文件放入组件中,并将 DLL 设置为密钥文件,并将组件设置为永久。
您现在应该能够进行重大升级并保留 XML 文件的内容,无论它是否已被修改为包含用户数据。
Can we get back to why you think you need a custom action for a moment?
Depending on the problem you are trying to solve you should be able to do one of two things
1) Put the XML file in it' own component, marked as keyfile and set to permanent.
2) Create a dummy DLL and give it a version of 1.0.0.0. Never increment this DLL's version number in the future. Put the DLL and XML file in a component with the DLL set to keyfile and the component set to permanent.
You should now be able to do major upgrades and persist the contents of the XML file regardless of whether it's ever been modified to include user data or not.