title: C#, Wix toolset. Why does deleting and updating delete a file that was created by my application?
body: <p>I have a WPF application, to create an installer, I chose the Wix toolset. My application creates a local database, it is not included in the lists of files for installation. When I uninstall the app, my DB file is deleted, this works, but when I update an application, the file is also deleted. Help me figure out how to ensure that the file is not deleted during the update, but is deleted when the application is only deleted.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Wix xmlns=&quot;http://schemas.microsoft.com/wix/2006/wi&quot;
       xmlns:util=&quot;http://schemas.microsoft.com/wix/UtilExtension&quot;&gt;
      &lt;?define ProductName=&quot;MyApp&quot;?&gt;
      &lt;?define TargetFileName=&quot;MyApp Desktop.exe&quot;?&gt;
      &lt;?define description=&quot;MyApp&quot;?&gt;
  
      &lt;Product Id=&quot;*&quot; Name=&quot;$(var.ProductName)&quot; Language=&quot;1033&quot; Version=&quot;1.0.8.0&quot; Manufacturer=&quot;$(var.ProductName)&quot; UpgradeCode=&quot;e7fa5ab6-bed7-4850-97e2-270bfd182983&quot;&gt;
  
          &lt;Package InstallerVersion=&quot;200&quot; Compressed=&quot;yes&quot; InstallScope=&quot;perMachine&quot; Description=&quot;$(var.description)&quot;/&gt;
  
          &lt;MajorUpgrade DowngradeErrorMessage=&quot;A newer version of [ProductName] is already installed.&quot;/&gt;
          &lt;MediaTemplate EmbedCab=&quot;yes&quot;/&gt;
  
          &lt;Feature Id=&quot;ProductFeature&quot; Title=&quot;Installer&quot; Level=&quot;1&quot;&gt;
              &lt;ComponentRef Id=&quot;ShortcutMenu&quot; /&gt;
              &lt;ComponentRef Id=&quot;ShortcutDesktop&quot; /&gt;
              &lt;ComponentRef Id=&quot;INSTALLFOLDER_Permission&quot; /&gt;
              &lt;ComponentRef Id=&quot;MyAppFolder&quot; /&gt;
          &lt;/Feature&gt;
  
          &lt;Icon Id=&quot;icon&quot; SourceFile=&quot;IconApp.ico&quot;/&gt;
          &lt;Property Id=&quot;ARPPRODUCTICON&quot; Value=&quot;icon&quot; /&gt;
  
          &lt;WixVariable Id=&quot;WixUIBannerBmp&quot; Value=&quot;Images/TopBanner.png&quot;/&gt;
          &lt;WixVariable Id=&quot;WixUIDialogBmp&quot; Value=&quot;Images/DialogBanner.png&quot;/&gt;
  
          &lt;Property Id=&quot;WIXUI_INSTALLDIR&quot; Value=&quot;INSTALLFOLDER&quot; &gt;&lt;/Property&gt;
  
          &lt;UIRef Id=&quot;WixUI_InstallDir&quot;/&gt;
  
          &lt;Feature Id=&quot;BlazorAppFeature&quot;
                   Title=&quot;BlazorWasmApplication&quot;
                   Level=&quot;1&quot;
                   ConfigurableDirectory=&quot;INSTALLFOLDER&quot;
                   AllowAdvertise=&quot;no&quot;
                   Absent='disallow'&gt;
              &lt;ComponentGroupRef Id=&quot;PublishedComponents&quot; /&gt;
          &lt;/Feature&gt;
  
      &lt;/Product&gt;
  
      &lt;Fragment&gt;
          &lt;Directory Id=&quot;TARGETDIR&quot; Name=&quot;SourceDir&quot;&gt;
              &lt;Directory Id=&quot;ProgramFilesFolder&quot;&gt;
                  &lt;Directory Id=&quot;INSTALLFOLDER&quot; Name=&quot;StructureIT&quot;&gt;
              
                      &lt;Component Id=&quot;MyAppFolder&quot; Guid=&quot;24f047db-b522-478e-b0aa-fcc552c2f1a2&quot;&gt;
                          &lt;RemoveFile Id=&quot;PurgeAppFolder&quot; Name=&quot;MyAppDB.db&quot; On=&quot;uninstall&quot; /&gt;
                      &lt;/Component&gt;
                  &lt;/Directory&gt;
              &lt;/Directory&gt;
  
              &lt;Directory Id=&quot;DesktopFolder&quot; Name=&quot;decktop&quot;/&gt;
  
              &lt;Directory Id=&quot;ProgramMenuFolder&quot; Name=&quot;MenuFolder&quot; &gt;
                  &lt;Directory Id=&quot;ApplicationProgramsFolder&quot; Name=&quot;Structure IT&quot; /&gt;
              &lt;/Directory&gt;
          &lt;/Directory&gt;
      &lt;/Fragment&gt;
  
      &lt;Fragment&gt;
          &lt;Component Id=&quot;ShortcutMenu&quot; Guid=&quot;302df662-167e-42b7-94ae-cb2ab4dec1a6&quot;  Directory=&quot;ApplicationProgramsFolder&quot;&gt;
              &lt;Shortcut Id=&quot;StartMenu&quot; Name=&quot;$(var.ProductName)&quot; Description=&quot;$(var.description)&quot; Target =&quot;[INSTALLFOLDER]$(var.TargetFileName)&quot; /&gt;
              &lt;RemoveFolder Id=&quot;RemoveShortcut&quot;  On=&quot;uninstall&quot;/&gt;
              &lt;Registry Root=&quot;HKCU&quot; Key=&quot;SoftWare\[Manufacturer]\[ProductName]&quot; Name=&quot;installed&quot; Type=&quot;integer&quot; Value=&quot;1&quot; KeyPath=&quot;yes&quot;/&gt;
          &lt;/Component&gt;
      &lt;/Fragment&gt;
  
      &lt;Fragment&gt;
          &lt;Component Id=&quot;ShortcutDesktop&quot; Guid=&quot;e6a03b11-01b2-45ba-b7b3-77b0c09cdd3d&quot; Directory=&quot;DesktopFolder&quot; &gt;
              &lt;Shortcut Id=&quot;ShortcutDesktop&quot; Name=&quot;$(var.ProductName)&quot; Description=&quot;$(var.description)&quot; Target =&quot;[INSTALLFOLDER]$(var.TargetFileName)&quot; /&gt;
              &lt;RemoveFolder Id=&quot;RemoveDesktopFolder&quot; Directory=&quot;DesktopFolder&quot; On=&quot;uninstall&quot; /&gt;
              &lt;Registry Root=&quot;HKCU&quot; Key=&quot;SoftWare\[Manufacturer]\[ProductName]&quot; Name=&quot;installed&quot; Type=&quot;integer&quot; Value=&quot;1&quot; KeyPath=&quot;yes&quot;/&gt;
          &lt;/Component&gt;
      &lt;/Fragment&gt;
  
      &lt;Fragment&gt;
          &lt;DirectoryRef Id=&quot;INSTALLFOLDER&quot;&gt;
              &lt;Component Id=&quot;INSTALLFOLDER_Permission&quot; Guid=&quot;76f2583f-d81a-4ea7-a76a-0eb08732b3e0&quot;&gt;
                  &lt;CreateFolder&gt;
                      &lt;util:PermissionEx User=&quot;Users&quot; GenericAll=&quot;yes&quot;/&gt;
                  &lt;/CreateFolder&gt;
              &lt;/Component&gt;
          &lt;/DirectoryRef&gt;
      &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>