Visual Studio 安装项目 - 有条件安装文件

发布于 2024-10-07 20:08:02 字数 318 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思念满溢 2024-10-14 20:08:02

您需要转到“启动条件”选项卡并在目标计算机中搜索要检查的文件。启动条件将允许您指定属性的名称,如果文件存在,它将设置为文件的路径,否则将为空。您现在可以使用此属性作为文件的条件。

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.

活泼老夫 2024-10-14 20:08:02

我能够使用启动条件来设置属性,并将其用于文件的条件安装,因此我将“heavyd”标记为正确答案。但是,无法按照建议有效使用文件搜索(请参阅答案的评论)。相反,我使用了带有 MSI ComponentID 的 Windows Installer 搜索(VS 2008 安装项目中可用的三种搜索类型之一),如下所示(我找到了该技术 此处):

  1. 产品 1 已安装并具有名为 MyFile.txt 的文件。
  2. 您使用 ORCA(来自 Windows Installer SDK)查看文件表,并找到代表 MyFile.txt 的行。
  3. 您获取 Component_ 列的值,然后打开组件表。
  4. 在组件表中,您可以在 Component 列中找到具有 Component_ 值的行,并获取 ComponentID。将此值复制到剪贴板。关闭奥卡。
  5. 在安装项目中,打开启动条件编辑器并添加 Windows Installer 组件搜索。对于新搜索的 ComponentID 属性,粘贴 ComponentID。
  6. 复制 Property 属性。它应该类似于 COMPONENTEXISTS1。
  7. 打开文件系统编辑器并选择应用程序文件夹,然后选择要有条件安装的文件。
  8. 将 Condition 属性编辑为 COMPONENTEXISTS1 = FALSE。
  9. 如果您希望每次运行安装程序时(不仅仅是第一次)评估条件,请将 Transitive 属性设置为 true。
  10. 现在,只有当 MyFile.txt 尚不存在时才会安装。

此技术有一个警告:对安装进行修复将导致文件被删除,即使该文件被标记为永久!不好。我通过添加一些自定义操作(调用 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):

  1. Product 1 is installed and has a file named MyFile.txt.
  2. You use ORCA (from the Windows Installer SDK) to view the File table, and find the row that represents MyFile.txt.
  3. You get the value of the Component_ column and then open the Component Table.
  4. In the Component Table you find the row that has the Component_ value in the Component column, and get the ComponentID. Copy this value into clipboard. Close ORCA.
  5. In your setup project, open the Launch Conditions Editor and add a Windows Installer Component Search. For the ComponentID property of the new search, paste the ComponentID.
  6. Copy the Property property. It should be something like COMPONENTEXISTS1.
  7. Open the File System Editor and select the Application Folder, then select the file you want to conditionally install.
  8. Edit the Condition property to be COMPONENTEXISTS1 = FALSE.
  9. Set the Transitive property to true if you want the condition to be evaluated each time the installer is run (not just the first time).
  10. Now, MyFile.txt will only be installed if it is not already there.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文