0

I have been successfully using an exe (output of console app that i wrote) along with its application config file for a while. When i zipped them and sent it to my manager, he asked if i could get rid of the app.config file so the only thing that he copies in future is the exe.

Here is a gist of what my console app does. For example, my app.config has the following.

 <userSettings>
        <myapp.Properties.Settings>
            <setting name="productline" serializeAs="String">
                <value>Electronics</value>
            </setting>
</userSettings>

When i run the app like

c:\>myapp.exe -productline Mechanical -save

it will update the productline settings to Mechanical. When i run my app again, the productline is retained as Mechanical until i change it again.

Back to the problem, I thought i will get rid of the app.config file and have a static variable 'productline' and update it. However, when i tested, the static variable is overridden only till i run the exe one time. Next time i run the exe, it goes back to default 'Electronics'. I assume the second time i run the exe is like running the web application with iisreset so the static variables are fresh again.

What is the best approach here? Can an app.config be embedded into the exe, so i can still use it but the output will be just one exe file? Or what is the alternate way to save and retain the variables in this scenario ?

Jap Evans
  • 1,097
  • 8
  • 22
  • 42
  • where does it save ? – Renuka Deshmukh Mar 10 '16 at 01:47
  • Why an alternative to app.config instead of using app.config? http://stackoverflow.com/questions/10069254/app-config-file-in-console-application-c-sharp – Kory Gill Mar 10 '16 at 01:58
  • @RenukaDeshmukh I used to property settings. It gets save like in http://stackoverflow.com/questions/982354/where-are-the-properties-default-settings-stored – Jap Evans Mar 10 '16 at 02:51
  • @KoryGill As i said, when you give the exe to somebody, you have to give them the exe and the exe.config (app.config). I am just asking if it can be just one file (the exe). Just checking if there is a possibility – Jap Evans Mar 10 '16 at 02:53
  • My apologies, I misread your question. – Kory Gill Mar 10 '16 at 03:16

1 Answers1

0

If you have a constraint that prevents you from saving to a file then you could put your setting in the registry. The RegistryProxy class gives you easy access to the CurrentUser registry settings. This documentation provides methods for creating and manipulating those settings.

Scott Hannen
  • 27,588
  • 3
  • 45
  • 62