我们可以指示 Visual Studio 安装程序保留现有文件以便重新安装吗?
我有一个 Windows 窗体应用程序,其中包含已使用 Visual Studio 创建的安装程序 (.msi)。 我现在正在为 2.0 版创建一个新的安装程序,并将属性 RemovePreviousVersions
设置为 true。
现在,当我在 1.0 上安装 2.0 时,它会删除 1.0 并完全安装 2.0。
有没有一种方法可以告诉安装程序,如果您发现某些文件已安装(例如用于数据的 .xml 文件),那么不要覆盖它们?
我试图让我的 2.0 安装程序有两个目的:
- 为新用户从头开始安装
- 现有用户将升级但不会丢失他们的自定义设置
I have a Windows Forms application with an installer (.msi) already created with Visual Studio. I am now creating a new installer for version 2.0 with the property RemovePreviousVersions
set to true.
Now, when I install 2.0 over 1.0 it removes 1.0 and installs 2.0 completely.
Is there a way that I can tell the installer if you find some files already installed (like .xml files used for data) then don't override them?
I am trying to have my 2.0 installer serve the 2 purposes:
- Install from scratch for new users
- Existing users will upgrade but not lose their customizations
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VS中的部署项目不会覆盖文件。 发生的情况是,由于您将RemovePreviousVersions 设置为true,因此当您更改程序文件版本和安装项目的ProductCode GUID 时,它将首先卸载以前的版本,然后执行新版本的全新安装。
为了确保某些文件不会被覆盖,我通常将它们从内容或主输出文件(无论它们位于何处)中排除,然后将它们单独添加到安装项目中。 这样做,您可以单独设置这些文件的属性。 您正在寻找的属性称为“永久”,如果设置为 true,则永远不会卸载有问题的文件,因此永远不会用新版本覆盖它。这样做的唯一缺点是,当您卸载产品时,永久文件不会从目标位置删除,但就我而言(通常是本地数据库文件),这是一件好事;)
干杯!
[编辑]以上对于 VS 2008 SP1 来说是正确的,所以还没有在其他版本上尝试过。希望您使用相同的 VS 版本或者它适用于您使用的版本
[edit2] 哦,您也可以使用“Condition”属性来实现类似的功能,如果您这样做,请确保设置了“Transitive”。设置为 True,因此始终会评估 Conditions,但这是您可以考虑的另一种选择,除了这两个之外,我认为这对于 VS 部署项目来说几乎就是这样。
The deployment project in VS does not overwrite files. What happens is that since you have RemovePreviousVersions set to true, when you change your program file version and the ProductCode GUID of the setup project, it will first uninstall the previous version and then will do a clean install of the new version.
To make sure some files don't get overwritten, I usually exclude them from the Content or Primary output files (wherever they are located) and then add them separately to the setup project. Doing this, you can individually set properties for those files. The property you are looking for is called Permanent" that if set to true will never uninstall the file in question, and therefore will never overwrite it with a new version. The only drawback with this is that when you uninstall the product, the Permanent files will not get removed from their target locations, but in my case (usually local DB files), that's a good thing ;)
Cheers!
[edit] The above is true for VS 2008 SP1. Haven't tried it on other versions, so hopefully you are using the same VS version or it works for the version you use.
[edit2] Oh, also you could also use the "Condition" property to achieve something similar. If you do that, make sure that "Transitive" is set to True so the Condition is always evaluated. Haven't tried it with Conditions, but that's another option you could look at. Other than these 2, I think that's pretty much it for VS deployment projects.
当我遇到类似情况时,我所做的是:
由每个用户自定义且安装程序不应触及的文件不包含在 MSI 中(不包含在 Visual Studio 安装项目中)。 当应用程序第一次运行时,我通过代码生成了 XML 文件。
我将静态文件(例如用于填充下拉列表的数据)包含在 MSI 中,并且可以通过使用 Visual Studio 构建新的 MSI 来更新这些文件。
基本上不要在 MSI 项目中包含可自定义的文件。 在代码中为新用户创建它们。
我从未考虑过告诉 MSI 不要更新 MSI 文件中包含的某些文件。 我想出的解决方案对我来说是完美的。 我不知道是否可以做到。
我希望这有帮助。
When I was in a similar situation what I did was:
The files that were customized by each user and should NOT be touched by the installer were NOT included in the MSI (NOT in the Visual Studio Setup Project). When the app was run for the first time I generated the XML files through the code.
The files that were static (e.g. data that was used to populate Dropdownlists) I included in the MSI and I can update those by building a new MSI with Visual Studio.
Basically don't include customizable files in your MSI project. Create them in code for new users.
I never looked into telling the MSI not to update certain files that are included in the MSI file. The solution I came up with was perfect for me. I don't know if it can be done.
I hope this helps.