如果文件存在则 Visual Studio 安装项目有条件
我的应用程序有一个安装/部署项目,它将某些文件(*.dll、*.dat)输出到应用程序文件夹。
我想设置一个条件来检查文件当前是否存在。如果没有,请编写它,但如果有,请不要从包中安装它。是否可以?
该文件名为“database.dat”,在“属性”下,我看到一个“条件”属性,但我不熟悉要放在那里的内容。
任何意见都将受到高度赞赏。提前致谢。
编辑:
它已经存在的原因是,从以前的安装中,我们不想覆盖数据集/数据表中的数据。
I have a Setup/Deployment Project for my Application and it outputs certain files (*.dll, *.dat) to the Application Folder.
I would like a condition to be set to check if a file currently exists or not. If it doesn't, write it but if it does, don't install it from the package. Is it possible?
The file is called "database.dat" and under the Properties, I see a "Condition" attribute, but I'm not familiar with what to put in there.
Any input is greatly appreciated. Thanks in advance.
Edit:
Reason why it would already exist is that from a previous install there would be data from a DataSet / Data Table which we don't want to overwrite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要仅安装文件(如果尚不存在),请按照下列步骤操作:
在安装项目的“启动条件”视图下添加“搜索目标计算机”条目。
填写
FileName
属性和Folder
属性。Property
属性应该是您可以记住的常量,例如MY_AWESOME_FILE_EXISTS
”,找到要安装的组件并将其添加到Condition
属性“not MY_AWESOME_FILE_EXISTS
”就是这样。
来源(因为我只需要自己解决这个问题):
To only install a file, if it doesn't already exist, follow these steps:
Add a "Search Target Machine" entry under the "Launch Conditions" view in your setup project.
fill in the
FileName
property and theFolder
property.Property
property should be a constant you can remember, like "MY_AWESOME_FILE_EXISTS
"Condition
property "not MY_AWESOME_FILE_EXISTS
"That is all.
Sources (since I just had to figure this out for myself):
您应该安装数据文件作为测试,看看实际发生了什么。我这样说的原因是 Windows Installer 不会覆盖首次安装后已更改的文件。请参阅此规则:
https:// msdn.microsoft.com/en-us/library/windows/desktop/aa370531(v=vs.85).aspx
在我看来,您可能什么都不用做。
You should just install the data file as a test to see what actually happens. The reason I say this is that Windows Installer will not overwrite files that have been changed after they were first installed. See this rule:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa370531(v=vs.85).aspx
It seems to me you may need to do nothing at all.
Condition 属性正是您所需要的:Exists 条件。简化的示例是:
另请参阅此主题。
The Condition-attribute has just what you need: an Exists-condition. Simplified example is:
See also this topic.
不幸的是,如果您使用 [TARGETDIR] 文件夹,Darren 的解决方案将不起作用。就我而言,我有一个使用 Sqlite 数据库的 winformrs 应用程序,并且在升级应用程序时我不会覆盖数据库。
因此,我使用注册表检查来代替,当安装应用程序时,会在注册表中创建一个密钥,并在卸载时将其删除。因此,在升级时,我检查注册表项是否存在,如果存在,我会阻止使用数据库文件 Condition 属性复制空白数据库,正如 Darren 已经解释的那样。它工作正常。
Unfortunately, Darren's solution does not work if you use the [TARGETDIR] folder. In my case, I have a winfomrs app that uses an Sqlite db, and I don't won't to overwrite the DB when upgrading the app.
So, I used the Registry check instead, when the app is installed a key is created in the registry, and removed when unistalled. So when upgrading, I check if the registry key exists, and if it does, I prevent the blank db to be copied using the database file Condition property as already explained by Darren. And it worked correctly.
在安装项目上,右键单击要保留在安装文件夹中的文件,选择属性并将永久设置为 true。
On the Setup Project, right-click on the file you want to keep on the installation folder, select Properties and set Permanent to true.