Visual Studio Setup Project conditional if File Exists

£可爱£侵袭症+ 提交于 2019-11-27 22:17:36

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):

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.

Richard Flamsholt

The Condition-attribute has just what you need: an Exists-condition. Simplified example is:

<Copy Condition="!Exists($(DestPath)database.dat)"
      SourceFiles="$(SrcPath)database.dat"
      DestinationFolder="$(DestPath)"/>

See also this topic.

On the Setup Project, right-click on the file you want to keep on the installation folder, select Properties and set Permanent to true.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!