Visual Studio 安装项目 - 有条件安装文件
我有一个 VS 2008 安装项目。我只想安装目标系统上尚不存在的 XML 文件。安装程序会覆盖非版本化的规则文件确保文件在目标系统上没有被修改的情况下永远不会被覆盖。但我不想覆盖该文件。可以在文件的 Visual Studio 安装程序属性中为文件设置一个条件属性。用于检查文件是否存在并仅在文件不存在时才进行安装的 Condition 属性的正确语法是什么?
I have a VS 2008 Setup project. I only want to install an XML file if it does not already exist on the target system. The installer overwrite rules for non versioned files ensure that a file will never be overwritten if it has not been modified on the target system. But I want to never overwrite the file. There is a Condition property that can be set on a file in the Visual Studio installer properties for a file. What is the correct syntax for the Condition property to check for existence of file and only install if it is not there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要转到“启动条件”选项卡并在目标计算机中搜索要检查的文件。启动条件将允许您指定属性的名称,如果文件存在,它将设置为文件的路径,否则将为空。您现在可以使用此属性作为文件的条件。
You will need to go to the Launch Conditions tab and search the target computer for the file you want to check for. The launch condition will let you specify the name of a property it will set to the path of the file if it exists, otherwise it will be empty. You can now use this property as the condition on your file.
我能够使用启动条件来设置属性,并将其用于文件的条件安装,因此我将“heavyd”标记为正确答案。但是,无法按照建议有效使用文件搜索(请参阅答案的评论)。相反,我使用了带有 MSI ComponentID 的 Windows Installer 搜索(VS 2008 安装项目中可用的三种搜索类型之一),如下所示(我找到了该技术 此处):
此技术有一个警告:对安装进行修复将导致文件被删除,即使该文件被标记为永久!不好。我通过添加一些自定义操作(调用 vbscript 文件)来备份和恢复我的文件来解决这个问题。
仅仅实现如此简单的任务是多么麻烦:在初始安装时安装一次文件,然后再也不会覆盖它。
如果有人有更好的解决方案,我洗耳恭听。
I was able to use a launch condition to set a property, and use this for a conditional install of a file, so I will mark 'heavyd' as the correct answer. However, was not able to use the file search effectively, as was suggested (see comments on the answer). Instead, I used a Windows Installer Search (one of the three types of searches available in a VS 2008 Setup Project) with the MSI ComponentID, as follows (I found the technique here):
There is one caveat with this technique: Doing a repair on the installation will cause the file to be deleted, even though the file is marked as Permanent! Not good. I worked around this by adding some custom actions (calling vbscript files) to backup and restore my file.
What a hassle to just achieve so simple a task: install a file once on initial install, then, never again overwrite it.
If anyone has a better solution, I am all ears.