Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Setup Project conditional if File Exists

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.

like image 587
mastofact Avatar asked Nov 05 '10 00:11

mastofact


2 Answers

To only install a file, if it doesn't already exist, follow these steps:

  1. Add a "Search Target Machine" entry under the "Launch Conditions" view in your setup project.

  2. fill in the FileName property and the Folder property.

  3. the Property property should be a constant you can remember, like "MY_AWESOME_FILE_EXISTS"
  4. in the "File System" view of your project, locate the component to install and add this to the Condition property "not MY_AWESOME_FILE_EXISTS"

That is all.

Sources (since I just had to figure this out for myself):

  • Condition Property
  • Conditional Statement Syntax
  • Conditional Install if a file exists
  • Searching for Existing Applications, Files, Registry Entries or .ini File Entries
like image 70
Daren Thomas Avatar answered Oct 25 '22 02:10

Daren Thomas


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.

like image 27
PhilDW Avatar answered Oct 25 '22 00:10

PhilDW