Search code examples
c#.netvb.netmy.settingssettings

.NET User Settings - Different for DEBUG and RELEASE Modes


I am hoping there is a solution to my issue with Application Settings. Each time I upgrade this application (WPF Desktop Application) I want my user settings to be persisted. To Achieve this I use the following code in my Application_Startup event;

If My.Settings.CallUpgrade = True Then
    My.Settings.Upgrade()
    My.Settings.CallUpgrade = False
    My.Settings.Save()
End If

This works perfectly and persists the user settings into the new version and results in user settings being persisted into a directory structure as follows;

C:\Users\Aaron\AppData\Local\Assistant\Assistant.exe_Url_1rohxsl103zsiltndvz23vqujpaafv4w
        ..\1.0.0.0
        ..\1.0.2.0

My Problem however is that the Base Folder is different for the assembly depending on which build configuration is used. Ie: If the Build Configuration is "DEBUG" then the directory which is used to persist user settings is as follows;

DEBUG Mode

C:\Users\Aaron\AppData\Local\Assistant\Assistant.exe_Url_1rohxsl103zsiltndvz23vqujpaafv4w

In release mode it is as follows;

RELEASE Mode

C:\Users\Aaron\AppData\Local\AssistantAssistant.exe_Url_od13shq40yxnxmu3xwepbkqf1bjqc34j

Totally different directories. Version 1.0.0.0 is left stranded in the DEBUG folder, and version 1.0.2.0 is put in the Release Folder. Naturally; Calling My.Settings.Upgrade() does not find any previous settings to upgrade because they are in a different folder.

The application is essentially considered to be two different assemblies depending on the Building Configuration.

I can understand when this might be desirable, but I have a circumstance where I want to distribute a "DEBUG" version so that I could attach to a remote running process etc. After a point in time I wish to distribute the "RELEASE" version of the application.

The problem however is that the user settings are not common to the two versions and essentially results in the loss of user settings.

Is there any solution which unifies the persistence and retrieval of User Settings across both Build Configurations/Versions of the assembly without resorting to rolling my own version of the Application Settings functionality?


Solution

  • No, that's not a real problem. It only happens on your machine, not the user's machine.

    The hashed directory name is affected by several properties of your EXE, one of them is the name of the directory where the EXE is installed. On your machine you have different directories, bin\Debug and bin\Release. The user's machine has only one, where ever the program is installed.

    You could just change the project setting so they are the same. Project + Properties, Build tab, Output path setting. Do so for the Debug configuration, change it to bin\Release. Good enough for testing and verifying that it works, you probably want to change it back after you feel good :)