I've got a Winforms app that has quite a few settings (.settings file). These are saved (as far as I can tell) in C:\Users\[User's username]\AppData\Local\[My program name]\[Build or something]\1.0.0.0\user.config but whenever I make a new build and a user runs that version, it makes a new [Build or something] folder and starts over with a "fresh set" of settings. What is the best practice for rolling over the settings from a previous version?
(Some settings I want to be "brand new" every time a new version is run and some settings I want to be copied from the last version)
I am using method described in this post (it says Clickonce but it is also applicable to other types of apps): https://blogs.msdn.microsoft.com/rprabhu/2005/06/29/client-settings-faq/
Q: Okay, but how do I know when to call Upgrade?
A: Good question. In Clickonce, when you install a new version of your application, ApplicationSettingsBase will detect it and automatically upgrade settings for you at the point settings are loaded. In non-Clickonce cases, there is no automatic upgrade – you have to call Upgrade yourself. Here is one idea for determining when to call Upgrade:
Have a boolean setting called CallUpgrade and give it a default value of true. When your app starts up, you can do something like:
if (Properties.Settings.Default.CallUpgrade) {
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.CallUpgrade = false;
}
This will ensure that Upgrade() is called only the first time the application runs after a new version is deployed.
Related
So I have a Windows Forms app that uses an encrypted connection string for the database.
Every quarter we change the database password, but the vendor only upgrades this app maybe every 12 or 18 months. So because of this, the "appname.exe.config.deploy" file that is hosted on the clickonce webserver would have our new password--but the hundreds of desktops would still have the old .config file with the old password because the verision has not changed.
I know I can delete the %userprofile%\AppData\Local\Apps\2.0\ folder (deleting potential unrelated click-once apps in the process), but we are talking hundreds of desktops and that's not really feasible here.
I would like to know if/how I can tweak the .manifest or whatever in order to "fake" the clickonce to think it needs to re-install. I can't imagine I'm the first one with this issue but I've found nothing satisfactory in my searches so far.
Thank you.
Unfortunately install\reinstall process initiating when no application installed or version has changed.
I don't understanding, why so important having old one ClickOnce version, because your clients will make update process anyway.
If new copy installation is fine for your clients, then you can set new "Application instance name". Your customers launch will do new instance installation of your application. I'm really don't know how to change this name from Visual Studio or Mage.exe, but you can download my utility from second download link here. [Choose] your application folder -> [Update] action -> Add any prefix for [Application instance name] field value (for example "_1") -> [Build] + [OK].
Anyway, version increment is the best solution for you.
I have a Full trust, online only, click-once application that relies on settings in the App.config --> appSettings collection.
Once published, the first time the application is executed, the settings are read and everything works fine. If I close the application and run it again, the items that are in appSettings are no longer there and appSettings.Count is equal to 0.
I have set the app.config as "Content" and to "Copy Always".
Any Idea what could be causing the items in appSettings to disappear? or a way to get around this?
Also, please note that the settings are only being read, and being used to determine how the application is run. We're not trying to manipulate the settings.
I guess you are using the settings wrong.
First of all, you need to mind the difference between application and user settings. Application settings are constant and can not be changed from your code (for example default values, connection strings, etc.). User settings are for settings that change when the application runs, usually because there is some sort of Settings dialog in your application.
Secondly, you need to access them properly. People tend to (and I don't know why) use things like ConfigurationManager or other stuff to access settings. It is far easier and less error-prone to use Properties.Settings.Default.SettingName for both application and user settings.
Changing a user setting would read like this:
Properties.Settings.Default.SettingName = settingValue;
Properties.Settings.Default.Save();
The call to Save is important, as otherwise the change will not be persisted.
Thirdly: No need to change the way app.config is included in your project. By default it will be renamed to applicationname.exe.config and will always be included in your output unless you say otherwise. The same goes for the ClickOnce installation: It will be included by default. You may actually break things if you play with this or the ClickOnce deployment settings for app.config! Revert them to default and leave them alone.
Now one case where the settings will be lost and reverted to defaults is when you update your application. In this case you will have to migrate your settings from the previously installed version, otherwise the user settings will be overridden with the default values from the installation. What you do to migrate the settings is:
Define a user setting named SettingsUpgradeRequired (name doesn't really matter - should be self-explaining, however) with a default value of true in the settings designer. Then, when your application starts, you do this:
if (Properties.Settings.Default.SettingsUpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.SettingsUpgradeRequired = false;
Properties.Settings.Default.Save();
}
This makes sure a migration of the settings only occurs when required. SettingsUpgradeRequired will only be true upon the first installation (in which case Upgrade does nothing) and after an update of your application, because - as I said - by default the configuration from the ClickOnce installation will override the previous configuration until you perform the upgrade.
I'm developing an application that saves various user settings (e.g. window locations, options, preferences). This is done using the syntax
Properties.Settings.Default.setting_name = "xxx";
Properties.Settings.Default.Save();
and
var x = Properties.Settings.Default.setting_name;
Here is an example of the underlying settings file path:-
C:\Users\user_name\AppData\Local\company_name\exe_name.vsh_Url_kxrjspzszls01bmlnkpeuf5cutfdioia\1.0.0.0
The problem is that each time I build and release a new version of the software, users are losing their settings. This is presumably down to the fact that the application exe version number is being included in the file path, so each time a new version is installed it starts over with a new, empty settings folder? Fortunately we're still in the dev phase so it's only a couple of internal users at present.
What's going on, and is there a way around it?
I'm also concerned because we have an existing product out in the field, and are due to release a new version shortly. I'm panicking that all these users will lose their settings and preferences when they upgrade.
So based on other SO questions and articles found on the web, I've written this short method that I now call during application startup:
private static void CheckForUserSettingsUpgrade()
{
if (!Properties.Settings.Default.UserSettingsUpgradeRequired)
{
return;
}
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UserSettingsUpgradeRequired = false;
Properties.Settings.Default.Save();
}
For this to work there must be a user-scope setting called UserSettingsUpgradeRequired with a default value of True.
After an upgrade (resulting in a new settings file being created) this setting's value will of course be true. In this scenario the above code will import all settings from the previous settings file (if any), set this upgrade flag setting to false, then save the changes. After the next upgrade, the flag's value will revert to true, and the process will repeat itself.
After doing a:
MyApp.Properties.Settings.Default.Upgrade();
How can I remove any previous setting files? The problem I'm having is I have a function where the user can reset his/her own data using:
Properties.Settings.Default.Reset();
However on the next start of the application, since the old user settings are still there it will be upgraded again.
How do you keep user.config settings across different assembly versions in .net?
seems to be what you are looking for.
So use Upgrade, UpgradeRequired=true or false, and Save : it would be quite long to explain all cases, but it is in fact quite easy to figure out what to do.
Looks like there is no way to do this other than doing it manually yourself.
So after a successful upgrade, you can remove the old version manually using file system methods.
I'd like to release some updates for a WinForm program, but to date I have simply released an all-new compile. People have to un-install the old version and install the new version.
EDIT: I'm using an auto-generated InstalWizard. It preserves my file strucutre and places the [PrimaryProgramOutput] in a particular directory. I forget what this is called.
I bet there's a way to get around this, but I don't know what it's called. As you may guess, searches for "updates" "new version" "install" and the other obvious things I've tried have generated an impressive number of irrelevant results. >_<
I suspect this process has a particular name, which should point me in the right direction, but if it doesn't please link to a tutorial or something.
I see from the tags you are using C#. Visual Studio can create Setup projects for these kind of tasks. The setup projects als contain a property RemovePreviousVersion, which will remove a previous version if the versioning of your setup is correct and the GUID of the application stays the same.
See this link for more information:
http://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/
ClickOnce deployment is a great solution most of the time...
You can deploy to the web and when ever your users start the application it will check for updates and automatically update the application if there is a new version available.
It can also be configured not to update automatically but only to notify the user that there is a new version available and allow the user to control the update process.