0

I have a (very) old c# desktop app which I've inherited and I need to move hard-coded values into a settings class. This setting class belongs to a class library. However when I publish the main project (which is the windows application) none of the settings from the class library appear in the published app.config.

So : have a VS 2017 solution with two projects: a class library and a winforms app. Both have a Settings.settings class; but when I publish the winforms app the resulting app.config only has the settings from the winforms app project.

Do I have to move the settings from the class library to the main project to have the published in the app.config? (which would seem odd as the code for the front-end doesn't use these settings directly)

Or is there some way I can ensure the settings in the class library are included in the app.config when publishing?

atamata
  • 997
  • 3
  • 14
  • 32
  • I don't know about others more experienced C# devs, but I don't have enough data to answer your question. I would need to see exactly what you talk about, in order not to mis interpret your wordings – Adelin Feb 07 '19 at 11:34
  • In short: I have a VS 2017 solution with two projects: a class library and a winforms app. Both have a Settings.settings class; but when I publish the winforms app the resulting app.config only has the settings from the winforms app project. – atamata Feb 07 '19 at 11:41
  • 1
    app.config is only loaded for the startup project, you'll need to include the class library settings into your app config file. – Chris Pickford Feb 07 '19 at 11:48
  • The winforms project will only have the settings from the existing project - you could add a link in the winforms project to the settings file in the other project - https://learn.microsoft.com/en-us/previous-versions/windows/apps/jj714082(v=vs.105) and this may combine the two without actually moving the settings file? – MikeS Feb 07 '19 at 11:59

1 Answers1

0

The "App.Config" file is populated from the "resources" tab in your project properties. If you make a "settings" class ('SettingsClass.cs'), this will indeed not visibly show up in the compiled product. such a class is useful to make it easier to find and change values during the design process, but it does not allow for easy updates (although it also makes it harder for end-users to inspect said settings).

if you want to be able to easily see and change values in the compiled product (trough an updater, for example); you will need to use the project properties, or use some other method (excel file, xml file, sql database), with a (custom) reader class

ThisIsMe
  • 274
  • 1
  • 5