28

In a C# Winforms-App I have several user settings stored.

Is there an easy way to clear those settings each time I start debugging the project from Visual Studio 2008?

Otherwise it always starts up with the settings from the last debug-session.

johnnyRose
  • 7,310
  • 17
  • 40
  • 61
Reinhard
  • 295
  • 1
  • 4
  • 5

6 Answers6

63

Had the same question and found an answer here: https://stackoverflow.com/a/2117359/488794

Properties.Settings.Default.Reset()

You can use this following statement to only reset if you're debugging:

if(Debugger.IsAttached) 
   Settings.Default.Reset();

tested VS2012 .Net 4.0 (Reference)

Community
  • 1
  • 1
Smolla
  • 1,711
  • 2
  • 20
  • 18
21

Add a pre-build action to delete:

%USERPROFILE%\Local Settings\Application Data\[AppName]\...\[Version]\user.config

or if your version number changes alot just delete

%USERPROFILE%\Local Settings\Application Data\[AppName]\

Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
  • 1
    Any chance you would know how to do the same thing for VS 2010??? I just messed up my debugger view and can't figure out how to get back to default... (grrr GUIs...) – Trevor Boyd Smith Sep 30 '10 at 22:13
  • 10
    I would recommend using the system variable `%localappdata%` instead. On my Windows 10 system for example, the folder `%USERPROFILE%\Local Settings` does not exist. – AeonOfTime Jan 06 '17 at 12:10
  • 1
    On Windows 10, it's called AppData but there is more to it than this as despite removing the folder the settings kept getting loaded. Ended up using the answer from Smolla, which did the trick – ManyRootsofAllEvil Jan 19 '17 at 15:28
8

Adding to the above answers, here a copy-paste solution that works for most settings:

rmdir /q /s %localappdata%\[company name]\[AppName]

Note that for most cases it's best to delete everything under %localappdata%[company name]. Check the app data stored there and choose what's best for you.

Asaf R
  • 6,880
  • 9
  • 47
  • 69
2

Run->Type "appdata"

Navigate to Local->/

Delete all files related to the project

sebastso
  • 170
  • 1
  • 1
  • 8
0

Here are two possible ways to do it:

  • use either the pre build or post build event command line, you put delete commands and such in there or run a batch file or script

  • have a play with the Start Action options of the start up project, you can specify an external program with command line arguments to be run first

slugster
  • 49,403
  • 14
  • 95
  • 145
0

Based on other answers: just search on C: or C:\Users\<YourUser> for user.config and delete or rename that file.

GoTo
  • 5,966
  • 2
  • 28
  • 31