views:

345

answers:

1

Hi, In order to have neater app distribution I have made app.config file to be embedded resource, since it only contains default values. However, the app now cannot be debugged, it throws an exception (ConfigurationErrorException). But when released, the app runs fine. Is there any way how to get it working in the debug time too? Thanks

A: 

I hope you are aware of the fact that this is not the intended behaviour? How do you extract the app.config at runtime? How do you get the values from the settings? The app.config file is not distributed as "app.config", but as "yourprogramname.exe.config". Which one do you embed?

If you embed the config file, you have no way of changing values. Why do you use the config file instead of hardcoding the values?

When you say that the app runs fine when you release-build it: I'm pretty sure that the values are not taken from the config file, but from the default values of the Settings class.

To make a long story short: I doubt that your approach will work.

Thorsten Dittmar
Yes that is why I am asking - I cannot see why there has to be app.config (in the solution explorer), when the changed values are stored in local user appdata.
Petr
The app.config file is an XML file that contains both application and user settings as you design them (default values). If you change user settings and save them, they are stored on a per-user basis. Application settings can only be changed by editing the config file. If you only use fixed application settings you never use, it's better to just define them as constants within code and not to use app.config at all. Embedding it won't work.
Thorsten Dittmar
Sorry, that should have been: "If you only use fixed application settings you never CHANGE, it's better..."
Thorsten Dittmar
Well, and what if I need to have setting that is configurable by user and also have default values?
Petr
Your original question was: When I embed the config file as a resource, I get exceptions when debugging. My solution is: do not embed the config file, but simply don't distribute it to the user. That way you can debug on your system, but defaults will be used when the user runs your application.
Thorsten Dittmar
But I cannot exlude it, in the application files its in Required group. You just mean delete it after release?
Petr
Set the build type to none - then it shouldn't be included.
Thorsten Dittmar
It is by default..but it always appear when released.
Petr
Are you ClickOnce-Deploying?
Thorsten Dittmar
I am sorry I do not know what does this option mean..I am working in C# for year but I never make deployment..until now (did modules and classes for projects only)
Petr
There are several ways of deploying .NET applications. One is to just copy it to the target machine (XCOPY-Deployment), one is to generate a setup file (see projects in Visual Studio), one is so called ClickOnces. Here, the app is stored on a web server or file share along with other data, and users can just open up a html page to install the application. The installation is on per user basis and requires app.config. If you create MSI setup, just do not copy app.config file to user's machine and your fine.
Thorsten Dittmar
Oh, that would explain a lot of things - where can I change the type of deployment?
Petr
You don't change it. If you want to create an installer, add a new deployment project to your solution and configure it to use the output from your application project. If you want to use ClickOnce, go to the project properties. There should be a Deployment Tab (don't know what it's called in English - not using English version) where you configure settings for ClickOnce and perform the deployment. You wrote above about required components - this list is for ClickOnce only and has nothing to do with what's installed by an MSI setup.
Thorsten Dittmar
Thank you! I just want to make simple executable without any setup etc. So what is the best choice?
Petr
Zip the EXE, leave out the exe.config file and tell the user to just unzip the file into a folder of his own choice.
Thorsten Dittmar
Thanks. BTW in VS Express there are not Setup projects so I guess it has to be ClickOnce.
Petr
Surprising I get downvoted for giving a valid answer that the OP considered a useful solution...
Thorsten Dittmar