ClickOnce and .NET 5: User settings not updated
Asked Answered
W

2

5

I've updated one of my WPF apps from .NET Framework 4.7 to .NET 5. It uses the ClickOnce Installer to install updates. Since the change to .NET 5, I'm using the AssemblyVersion for setting the version instead of rely on the ClickOnce version, but the ClickOnce ApplicationVersion is also set.

Additionally I'm using application settings (user.config file) to store some user settings. Since the update to .NET 5, the user settings are always deleted after an update. I tought it is because of the different AssemblyVersion, but as far as I understand this site, the config file sould be merged by ClickOnce automatically.

Also a Settings.Default.Upgrade() didn't change anything. The user.config is still not existing for the updated version and therefore, no settings could be loaded from previous verions.

Did I understand something wrong? Should it work or do I have to change anything?

Thank you in advance for your help :)

Wysocki answered 4/3, 2021 at 14:35 Comment(2)
Did you check this: "you must make sure this file is included with your application's other files when you populate your application manifest."Pablo
I don't really get what this means. Where can I add this file to 'other files'? I mean there is only the Settings.settings file in my project and no 'user.config' file. I don't use mage.exe - at least not directly. I'm just executing `msbuild /target:publish'.Wysocki
C
8

I have had the same issue. Signing the assembly of the WPF project did the trick for me and fixed the problem.

  • Project properties -> Singing -> "Sign the assembly"
  • Create a strong name key file
Chemotaxis answered 4/10, 2021 at 10:11 Comment(2)
Nice, that seems to work. Why is this not documented? Almost a half year of confusion o.OWysocki
This is working for me with .Net 6 and WPF. Here is documented how to create the strong name key file: learn.microsoft.com/en-us/biztalk/core/…Comedy
U
1

Putting this in the main form loaded event worked for me:

if (Properties.Settings.Default.UpgradeRequired)
{
    Properties.Settings.Default.Upgrade();
    Properties.Settings.Default.UpgradeRequired = false;
    Properties.Settings.Default.Save();
}

Set a Setting in settings called UpgradeRequired to true This way every time the program gets updated, the Upgrade method gets called and settings get carried forward to the next version.

Ukrainian answered 4/10, 2022 at 18:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.