-
November 27th, 2012, 10:50 AM
#1
Can I stop Visual Studio 2008 from overwriting my application configuration file?
A colleague wrote an application named "cranesimulator" in C# and Visual Studio 2008 that contains settings in a configuration file. There is a file in the project named "app.config". When the project gets built, that file gets copied into cransesimulator.exe.config in the project output directory.
If I want to change a simulation parameter such as the time rate (say from 1 real second per 1 simulated minute to 1 real second per 10 simulated seconds), I can change cranesimulator.exe.config. But if I have to rebuild the cranesimulator project, app.config gets copied over the top of the exe.config file, and my changes get lost. Is there any way to stop VS 2008 from replacing the exe.config file?
Or is there some way I can change what file the application is looking for? ConfigurationManager.OpenMappedExeConfiguration() seems to do what I want, if I understand the documentation correctly.
Thank you very much.
RobR
-
December 1st, 2012, 06:53 PM
#2
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
The simplest way is to change the app.config file located in the project's directory. If you make changes to this file, it will get copied over and renamed to myproject.exe.config.
-
December 3rd, 2012, 08:55 AM
#3
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
Thank you for that reply.
Unfortunately, that is not going to help. I think that the use of app.config in this application was a poor choice. The problem is that the configuration parameters are likely to change as various tests are performed, and the designer should have recognized that fact. That leads to two completely different test scenarios. If the program is run in debug mode from inside Visual Studio, then I have to remember to set my parameters in app.config. If I am finished with debugging for the moment and am running tests from a command line, I have to remember to set my parameters in myprogram.exe.config. And as soon as I go back into debugging mode, the parameters I had set in myprogram.exe.config will get lost.
And then there's the difficulty of working with System.Configuration. I found I needed another application to support the testing I'm doing. I tried to use the same configuration file, but I couldn't get it to work. I wanted to use System.Configuration.OpenMappedConfigurationFile to bring in the original application's configuration, but it didn't work. I spent the better part of a day on it. Finally, I stripped out reliance on app.config and System.Configuration from the original application and replaced it with System.Xml.Linq, and the whole problem went away.
-
December 3rd, 2012, 01:36 PM
#4
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
Ok. I believe there is a basic misunderstanding for what the app.config file is used for. It's for read-only settings that are read during program startup.
If you need some other functionality (like r/w settings), you'll need to use something other than the default app.config mechanism.
-
December 3rd, 2012, 01:42 PM
#5
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
There are read-only settings, but they need to be changed for different test configurations. App.config and its automatic overwriting of myprogram.app.config makes it unsuitable for that purpose.
-
December 3rd, 2012, 03:51 PM
#6
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
Program configuration settings (preferences if you will) are best stored in the database that the application uses (if it is using one). Otherwise, have the application create and manage it's own configuration file or use the registry - though I'd recommend the former.
-Max
-
December 3rd, 2012, 03:57 PM
#7
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
See "http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx". Read the parts pertaining to user settings and user.config. Basically, the settings in the app.config should be read-only default settings. If you have settings that you need to change at run-time on a per user basis, they go into a user.config file associated with that user's local profile.
-
December 3rd, 2012, 05:27 PM
#8
Re: Can I stop Visual Studio 2008 from overwriting my application configuration file?
Originally Posted by RobR
App.config and its automatic overwriting of myprogram.app.config makes it unsuitable for that purpose.
Yes, it simply isn't designed to work that way. During testing, if you need to change the settings, do it on the fly to the *.exe.config file before launching the app and running your tests. Or do something else that fits your needs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|