Avoid overwriting existing files when installing a newer version

I have a VS2008 Windows Applications Project (WinProject) that is deployed in an Installation Project (InstallationProject) that has the RemovePreviousVersions property set to True.

In my application, for every configuration made by the user, winapp writes the configurations to an XML file (stored in the C: \ Application Name \ Files \ folder), which also includes the path where the configuration was saved.

Now, when I create new versions of the installer, this folder and files are overwritten as the AlwaysCreate flag is set to True .

My question is, how can I avoid reloading these old files and at the same time get the updated file from the installer.

Example: file content

  <PriceFiles>
    <Name>arr</Name>
    <Path>C:\NewTool\arr.xml</Path>
    <UserDefined>true</UserDefined>
  </PriceFiles>
  <ReferenceProjects>
    <Name>studio</Name>
    <Path>C:\NewTool\ReferenceProjects\6cd3a9e9-ad65-475e-953b-128915a496cd.xml</Path>
    <UserDefined>true</UserDefined>
    <CreatedBy>Admin</CreatedBy>
  </ReferenceProjects>

      

Thanks in advance

+2


a source to share


4 answers


Perhaps you should write your config files to the ApplicationData folder. You can get the path to it:



Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

      

0


a source


Is there a reason not to use built-in user config options ?

In terms of stopping these files from being overwritten, I don't think there is a way to do this with the default MSI setting.

Do you want to merge between the configuration settings already installed on the machine and those that are installed, and update the configuration file with any settings that do not exist on the machine? or do you just want these files not to be overwritten and other parts of the application installed?



The simplest option I can think of is to have no config files in the installer at all, and have the app handle that case and create them if it can't find them.

Otherwise, you probably need to run some post-install script that modifies or installs the config files if they don't exist.

One caveat is that my knowledge of MSI is far from exhaustive, so there might be a way not to overwrite certain files.

0


a source


Yes, there is a reason not to use the built-in config options to configure my application prior to installation.

Actually the work I need to do is what you guessed it ... ie "create a config file with default content if the file doesn't exist on the machine" "merge config settings if the file is already on the machine"

Should I use Custom Installer for this check?

Vatsa relationship

0


a source


Property

Usually when we add external files to the application folder in Setup and Deployment

, click on them properites

and select the option Permanent: True

and Exclude: False

. This will not overwrite existing files (in the installation path).

Also, if you want to make it Myproduct.exe.config

permanent, you can add this file to your application folder in Setup and Deployment

and configure your properties as I said earlier. This will prevent overwriting Myproduct.exe.config

. I tried this, worked for me. But when i build my project i used warning likeTwo or more objects have the same target location ('[targetdir]\Myproduct.exe.config').

0


a source







All Articles