0

I have two applications written in C#. Both do the same basic task; one has a UI and is designed to set-up and configure a process and the other is a console application designed to run the process as configured on a schedule.

I have them set up in Visual Studio as two different projects in the same Solution with a separate library they both reference doing all the hard work. Having a single application work in both circumstances doesn't seem to be a recommended approach, so I have split the UI/Console variants out accordingly.

The problem is that I am trying to share configuration - just a few string values; connection strings, file locations and so on - between them. This is set up from the UI version but the Console project can't run without it.

Initially I just had the settings in my Application.exe.config but when I installed the application using a regular installer, it died the moment it tried to save the configuration file because of file permissions.

Now I have a Settings object in the shared library with these values as User Settings made accessible through a wrapper class that both other projects can access and update. That solves my update problem, but now my Console application can't read the settings values that have been set by the UI.

I could just drop them in a configuration file and handle it manually - that would probably have been a little faster by this point than trying to do it the Windows way - but I feel like this must be something that the platform supports somehow.

How should I store my configuration so it is available to two different applications (created within the same Visual Studio Solution) and the settings used by both applications can be updated and saved by the user?

glenatron
  • 11,018
  • 13
  • 64
  • 112
  • 1
    I'm not sure what you mean by the 'Windows way' but the app.config route is a good approach. Yes the UI app would need elevated privileges to write to that file if the app is installed under Program Files but you can just run as admin to resolve that. Another approach would be a custom shared config file under the user profile that you point both apps to manually. Serialize/Deserialize your settings object to/from that file and you're done. – HasaniH Mar 30 '22 at 16:31
  • @HasaniH I really mean if there's a built-in way to do this or one that goes with the flow of the platform, but if there isn't then I can hand-roll it just fine. If you turn this into an answer that probably is the solution. – glenatron Mar 31 '22 at 08:43

1 Answers1

0

Use the ConfigurationManager class to manage your app.config (see the docs here) if you want the built-in way. You may need to run your UI with elevated privilege to edit the config or you can make the config files user specific and stash them under each user's profile.

HasaniH
  • 8,232
  • 6
  • 41
  • 59