0

I've run into some issues with the Visual Studio Properties.Settings.Default method of saving config values persistently in a user.config file in AppData. The main problem is the way the file is stored - it's location (and the file contents) when running unit tests compared to the main executable. It also changes along with the assembly version.


Update:

To clarify (per comments), when running the app different ways (and from different projects in a solution), the Properties.Settings.Default auto-generated functionality uses a different folder to store the user.config file in each case:

  1. When running the application directly (with the company name in the assembly information empty):
    • [Documents]\AppData\[MyApp]\[MyApp.Exe]_Url_[hash]\1.0.0.0\user.config
  2. When running the Resharper test runner:
    • [Documents]\AppData\JetBrains\[MyUnitTestProjectName]_StrongName_[hash]\109.0.0.0\user.config
  3. When running the xunit test runner within Visual Studio:
    • [Documents]\AppData\Microsoft_Corporation\[MyUnitTestProjectName]_StrongName_[hash]\15.0.26720.2\user.config

Since the user.config file is stored and looked for in different places, depending on whether I'm running the app directly or running unit tests, when I save info out of my normal running exe, I cannot access that same info while running unit tests.

Similarly, if I switch from a GUI frontend to a Console frontend, I have the same issue, because the file is specific to the run-time executable parent (I think). I just want a single config that is saved and used for any part of a given solution that wants to access it.


So, is there another built-in way to do configuration management in .NET, or another way to solve this issue?

I see lots of applications that have custom named config files and other data in their AppData folders - are they using a standard .NET library for that?

LightCC
  • 9,804
  • 5
  • 52
  • 92
  • What issues have you run into? App settings are saved to the **.exe.config* file. User settings get saved to **c:\users\\AppData\** – CodingYoshi Oct 26 '17 at 03:30
  • This is for user settings - it gets saved to different files for the main executable and for unit tests, because those are run from a unit test runner (either visual studio or something else), so I end up with different settings files for my unit tests, when I'd like to pull some of the same setting info from them. I guess mainly if I could control the location of the settings file that would probably solve the issue. – LightCC Oct 26 '17 at 03:34
  • https://stackoverflow.com/questions/2518772/how-to-change-net-user-settings-location – CodingYoshi Oct 26 '17 at 03:38
  • @CodingYoshi That's fine, and there are plenty of potential solutions out there, but is everybody just hacking their own solution for this use case? Isn't there a standard solution that someone has put together and is commonly used - even if just a package on nuget, etc.? – LightCC Oct 26 '17 at 13:37
  • Updated to Question to clarify the issue. Someone outside of SO pointed out "Configuration Manager" to me, I might look into that. – LightCC Nov 03 '17 at 20:21

0 Answers0