C# application user settings maintained during update











up vote
0
down vote

favorite












I have a C# application that currently stores user settings/configurations in a separate xml file. My application uses a wix installer and id like to know if there is a way to preserve the xml file should the user be installing a newer version of the application if they install without first removing the older version. The xml file is stored in the CommonAppData folder and should be removed if the application is uninstalled.



Backup question - Is there a better way of doing this than my current method?



UPDATE



I have implemented the following code:



    <CustomAction Id="Cleanup_Files" Directory="CompanyFolder" ExeCommand="cmd /C RD 
&quot;[CommonFolder]&quot; /s /q" Execute="deferred" Return="ignore" HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="Cleanup_Files" Before="RemoveFiles" >
Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE
</Custom>
</InstallExecuteSequence>


This removes the CommonFolder directory as required on uninstall but it still removes the directory when upgrading. What changes are necessary to achieve this?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have a C# application that currently stores user settings/configurations in a separate xml file. My application uses a wix installer and id like to know if there is a way to preserve the xml file should the user be installing a newer version of the application if they install without first removing the older version. The xml file is stored in the CommonAppData folder and should be removed if the application is uninstalled.



    Backup question - Is there a better way of doing this than my current method?



    UPDATE



    I have implemented the following code:



        <CustomAction Id="Cleanup_Files" Directory="CompanyFolder" ExeCommand="cmd /C RD 
    &quot;[CommonFolder]&quot; /s /q" Execute="deferred" Return="ignore" HideTarget="no"
    Impersonate="no" />
    <InstallExecuteSequence>
    <Custom Action="Cleanup_Files" Before="RemoveFiles" >
    Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE
    </Custom>
    </InstallExecuteSequence>


    This removes the CommonFolder directory as required on uninstall but it still removes the directory when upgrading. What changes are necessary to achieve this?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a C# application that currently stores user settings/configurations in a separate xml file. My application uses a wix installer and id like to know if there is a way to preserve the xml file should the user be installing a newer version of the application if they install without first removing the older version. The xml file is stored in the CommonAppData folder and should be removed if the application is uninstalled.



      Backup question - Is there a better way of doing this than my current method?



      UPDATE



      I have implemented the following code:



          <CustomAction Id="Cleanup_Files" Directory="CompanyFolder" ExeCommand="cmd /C RD 
      &quot;[CommonFolder]&quot; /s /q" Execute="deferred" Return="ignore" HideTarget="no"
      Impersonate="no" />
      <InstallExecuteSequence>
      <Custom Action="Cleanup_Files" Before="RemoveFiles" >
      Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE
      </Custom>
      </InstallExecuteSequence>


      This removes the CommonFolder directory as required on uninstall but it still removes the directory when upgrading. What changes are necessary to achieve this?










      share|improve this question















      I have a C# application that currently stores user settings/configurations in a separate xml file. My application uses a wix installer and id like to know if there is a way to preserve the xml file should the user be installing a newer version of the application if they install without first removing the older version. The xml file is stored in the CommonAppData folder and should be removed if the application is uninstalled.



      Backup question - Is there a better way of doing this than my current method?



      UPDATE



      I have implemented the following code:



          <CustomAction Id="Cleanup_Files" Directory="CompanyFolder" ExeCommand="cmd /C RD 
      &quot;[CommonFolder]&quot; /s /q" Execute="deferred" Return="ignore" HideTarget="no"
      Impersonate="no" />
      <InstallExecuteSequence>
      <Custom Action="Cleanup_Files" Before="RemoveFiles" >
      Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE
      </Custom>
      </InstallExecuteSequence>


      This removes the CommonFolder directory as required on uninstall but it still removes the directory when upgrading. What changes are necessary to achieve this?







      c# configuration wix installer settings






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked 2 days ago









      jhorwood28

      144




      144
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          The easiest thing to do is: do not insatall this XML file by the setup, but instead let it create by the application if it is not there. By this, an update will not touch the file.
          With this scenario it is also possible to migrate the settings from an older (or newer) version.



          However, the file will also remain on uninstall. If it is a requirement to remove it in this case, you can do this by a custom action with a condition like Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE






          share|improve this answer





















          • Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
            – jhorwood28
            2 days ago










          • A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
            – Klaus Gütter
            2 days ago












          • Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
            – jhorwood28
            yesterday










          • You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
            – Klaus Gütter
            yesterday




















          up vote
          0
          down vote













          The solution for me was to follow the advice of Klaus but with some additional changes to my product.wxs file. I had to add 'AllowSameVersionUpgrades="yes"' to the MajorUpgrade section.



              <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of 
          [ProductName] is already installed." />


          Thanks to Klaus for all of their advice!






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373596%2fc-sharp-application-user-settings-maintained-during-update%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            The easiest thing to do is: do not insatall this XML file by the setup, but instead let it create by the application if it is not there. By this, an update will not touch the file.
            With this scenario it is also possible to migrate the settings from an older (or newer) version.



            However, the file will also remain on uninstall. If it is a requirement to remove it in this case, you can do this by a custom action with a condition like Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE






            share|improve this answer





















            • Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
              – jhorwood28
              2 days ago










            • A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
              – Klaus Gütter
              2 days ago












            • Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
              – jhorwood28
              yesterday










            • You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
              – Klaus Gütter
              yesterday

















            up vote
            0
            down vote













            The easiest thing to do is: do not insatall this XML file by the setup, but instead let it create by the application if it is not there. By this, an update will not touch the file.
            With this scenario it is also possible to migrate the settings from an older (or newer) version.



            However, the file will also remain on uninstall. If it is a requirement to remove it in this case, you can do this by a custom action with a condition like Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE






            share|improve this answer





















            • Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
              – jhorwood28
              2 days ago










            • A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
              – Klaus Gütter
              2 days ago












            • Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
              – jhorwood28
              yesterday










            • You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
              – Klaus Gütter
              yesterday















            up vote
            0
            down vote










            up vote
            0
            down vote









            The easiest thing to do is: do not insatall this XML file by the setup, but instead let it create by the application if it is not there. By this, an update will not touch the file.
            With this scenario it is also possible to migrate the settings from an older (or newer) version.



            However, the file will also remain on uninstall. If it is a requirement to remove it in this case, you can do this by a custom action with a condition like Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE






            share|improve this answer












            The easiest thing to do is: do not insatall this XML file by the setup, but instead let it create by the application if it is not there. By this, an update will not touch the file.
            With this scenario it is also possible to migrate the settings from an older (or newer) version.



            However, the file will also remain on uninstall. If it is a requirement to remove it in this case, you can do this by a custom action with a condition like Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            Klaus Gütter

            814412




            814412












            • Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
              – jhorwood28
              2 days ago










            • A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
              – Klaus Gütter
              2 days ago












            • Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
              – jhorwood28
              yesterday










            • You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
              – Klaus Gütter
              yesterday




















            • Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
              – jhorwood28
              2 days ago










            • A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
              – Klaus Gütter
              2 days ago












            • Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
              – jhorwood28
              yesterday










            • You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
              – Klaus Gütter
              yesterday


















            Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
            – jhorwood28
            2 days ago




            Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file?
            – jhorwood28
            2 days ago












            A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
            – Klaus Gütter
            2 days ago






            A very simple approach is in this answer: stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding,
            – Klaus Gütter
            2 days ago














            Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
            – jhorwood28
            yesterday




            Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update)
            – jhorwood28
            yesterday












            You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
            – Klaus Gütter
            yesterday






            You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE?
            – Klaus Gütter
            yesterday














            up vote
            0
            down vote













            The solution for me was to follow the advice of Klaus but with some additional changes to my product.wxs file. I had to add 'AllowSameVersionUpgrades="yes"' to the MajorUpgrade section.



                <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of 
            [ProductName] is already installed." />


            Thanks to Klaus for all of their advice!






            share|improve this answer

























              up vote
              0
              down vote













              The solution for me was to follow the advice of Klaus but with some additional changes to my product.wxs file. I had to add 'AllowSameVersionUpgrades="yes"' to the MajorUpgrade section.



                  <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of 
              [ProductName] is already installed." />


              Thanks to Klaus for all of their advice!






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                The solution for me was to follow the advice of Klaus but with some additional changes to my product.wxs file. I had to add 'AllowSameVersionUpgrades="yes"' to the MajorUpgrade section.



                    <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of 
                [ProductName] is already installed." />


                Thanks to Klaus for all of their advice!






                share|improve this answer












                The solution for me was to follow the advice of Klaus but with some additional changes to my product.wxs file. I had to add 'AllowSameVersionUpgrades="yes"' to the MajorUpgrade section.



                    <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of 
                [ProductName] is already installed." />


                Thanks to Klaus for all of their advice!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                jhorwood28

                144




                144






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373596%2fc-sharp-application-user-settings-maintained-during-update%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]