Visual Studio Setup Project - conditionally install file

10,757

Solution 1

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.

Solution 2

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.

Share:
10,757
CyberMonk
Author by

CyberMonk

Updated on June 04, 2022

Comments

  • CyberMonk
    CyberMonk almost 2 years

    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?