使用WIX安装程序安装期间无法删除已部署的文件 [英] Unable to delete deployed file during installation with WIX installer

查看:202
本文介绍了使用WIX安装程序安装期间无法删除已部署的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WIX安装程序项目中,我们需要基于托管的自定义操作功能中的部署文件(称为FileA)生成一个新文件,称为FileB.换句话说,在组件声明中,我声明了FileA.在自定义操作中(发生在提交阶段),我需要基于FileA生成FileB.之后,由于FileA不再使用,我想在同一自定义操作中将其删除.

In our WIX installer project, we need to generate a new file, let's call it FileB, based on a deployed file, called FileA in a managed custom action function. In another word, in the component declaration, I declare the FileA. While in a custom action (which happens at commit phase), I need to generate FileB based on FileA. After that, since FileA is no use anymore, I want to delete it in the same custom action.

问题来了:默认安装文件夹为Program Files,不允许普通用户在自定义操作中将文件(生成FileB)添加到此文件夹中(我不是100%确定我是对的) ,但是在我的测试中就是这种情况.如果我将其安装在另一个文件夹中,则完全没有问题).因此,我认为我需要授予创建文件的权限.为此,我向包含FileA的组件添加了CreateFolder元素.整个组件的声明是这样的:

And here comes the problem: with the default installation folder, which is Program Files, the normal user is not allowed to add file (generate FileB) into this folder in the custom action (I am not 100% sure I am right, but it is the case in my test. And if I install it in another folder, there is no problem at all). So I think I need to give permission of creating file. In order to do that, I add a CreateFolder element to the component which includs FileA. The whole component declaration is something like this:

<Component Id='COMPONENT_NAME' Guid='MY_GUID'>
    <!--OTHER FILES IN THE COMPONENT-->
    ...
    <CreateFolder Directory='INSTALLDIR'>
      <Permission CreateFile='yes' User='Everyone' GenericAll='yes' Delete='yes'/>
    </CreateFolder>
    <File Id='MyFileA' Name='FileA'   Source='PATH_TO_FILEA' KeyPath='no' >
      <Permission GenericAll='yes' User='Everyone' Delete='yes'/>
    </File>
  </Component>

该组件实际上属于一个组件组,该组件组位于INSTALLDIR中.同一组件元素中还有其他文件的原因是,我希望另一个文件成为键路径,因此删除FileA不会造成该问题.现在FileB的生成工作正常.但是稍后在同一自定义操作中,删除FileA时遇到了问题.它只是说::拒绝访问路径'DEPLOYMENT_PATH_TO_FILEA'."我认为问题出在FileA声明中,这就是为什么我在File下的Permission元素中添加Delete ='yes',希望可以将其删除(尽管我不确定这是否意味着可以安装)删除).但我仍然收到此错误.谁能告诉我我做错了什么?

The component actually belongs to a component group, which resides in INSTALLDIR. The reason there is other files in the same component element is because I want another File to be the keypath, so that deleting FileA would not cause a problem of that. And now the generation of FileB is working fine. But later in the same custom action, I am experiencing the problem when deleting FileA. It just says that ": Access to the path 'DEPLOYMENT_PATH_TO_FILEA' is denied." I thought the problem lies in the FileA declaration, that's why I added the Delete='yes' in the Permission element under File, hoping to make it OK to delete it (although I am not sure whether this means in the installation it is possible to delete). But still I get this error. Can anyone tell me what I did wrong?

另一个问题是,我真的不知道这些CreatFolder元素的目的是什么.一方面:如果目的是创建目录结构,那么我认为(嵌套的)Directory元素已经可以做到这一点.以及为什么大多数时候您可能希望目录结构与组件结构分开(为什么组件仅使用目录引用来引用正确的目录),为什么要在Component元素下使用此类元素.其次,CreateFolder的默认Directory属性是组件所在的父目录.但是,通常有多个组件驻留在同一目录中,就像我在这里所看到的那样:多个组件位于同一个组件组中,其目录对INSTALLDIR的元素引用.因此,这些组件中只有一个具有CreateFolder元素,在我的案例中,其Directory属性是所有这些组件的父目录.真的很难理解这种结构.我想我对CreateFolder元素有一些误解.有人可以启发我使用CreateFolder吗?谢谢!

Another question is, I really don't know what is the purpose of those CreatFolder elements. For one thing: if the aim is to create the directory structure, I think the (nested)Directory elements already do that. And why to have such element under Component element when most of the time you probably want the directory structure to be separated with component structure(the components just use directory reference to refer to correct directory). Secondly, the default Directory property of CreateFolder is the parent Directory where the component resides in. But it is common that more than one components reside in the same directory, like what I have here: multiple components are in the same component group, whose directory element references to INSTALLDIR. So only one of these components has the CreateFolder element, whose Directory property in my case is the parent directory of all those components. It is really hard to understand this structure. I guess I have some misunderstanding of the CreateFolder element. Can someone enlighten me to usage of CreateFolder? Thanks!

谢谢!

推荐答案

此处要解决的许多问题.首先,您应该知道,如果禁用回滚,则不会执行Commit阶段自定义操作.您确实应该执行一个延迟和回滚的自定义操作.

A number of issues to address here. First, you should know that Commit phase custom actions don't execute if rollback is disabled. You should really have an deferred and rollback custom action.

第二,您不能告诉MSI安装文件然后删除它.这适得其反,只会导致今后的维修问题.更好的解决方案(假设您使用的是WiX DTF管理的自定义操作)是将FileA作为内容项包含在自定义操作项目中.这将导致文件在执行时存在于自定义操作的当前(临时)目录中.然后,您可以生成fileb.对于回滚,您可以删除fileb.

Second, you can't tell MSI to install a file and then go delete it. That's counterproductive and just causes servicing issues down the road. A better solution ( I'm assuming you are using a WiX DTF managed custom action ) is to include FileA as a content item in the custom action project. This will cause the file to exist in the current (temp) directory of the custom action while it execute. You can then generate fileb. For rollback, you can delete fileb.

您还需要编写一个RemoveFile元素来教导MSI在卸载时删除该文件.否则,由于MSI对您的进程外自定义操作创建的fileb一无所知,所以不会.

You'll also need to author a RemoveFile element to teach MSI to delete the file on uninstall. Otherwise it won't since MSI doesn't know anything about fileb created by your out of process custom action.

否则,了解fileb的内容将很有用.如果这是一个XML文件,可以将其安装为fileb,然后使用xml wix扩展名进行转换,则实施起来会更容易.

Otherwise it'd be useful to know what the contents of fileb are. It would be easier to implement if this was an xml file that could be installed as fileb and then transformed using the xml wix extension.

这篇关于使用WIX安装程序安装期间无法删除已部署的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆