views:

164

answers:

4

When I create a .NET Windows Service, there is an App.config file. When I compile the service, it creates a ServiceName.exe.config in the bin directory and there is also a ServiceName.vshosts.exe.config

Q1) What is the significance of multiple config files?

When I change a setting in the App.config it does not take effect until I uninstall the service, recompile it and reinstall the service. I tried making the setting change in both App.config as well as ServiceName.exe.config with no luck.

Q2) My understanding was that a config file makes it easier to make setting changes without having to redeploy the service.

Any response is appreciated

A: 

One is for debugging inside of Visual Studio and the other is for the real service.

The config file has to be deployed to the Windows System directory and your service restarted to pickup the changes.

JD
"deployed to the Windows System directory " -> I assume you mean C:\WINDOWS\system32 directory. It has a copy of the config file here as well?
A: 

You can get more details on this url --> http://blogs.msdn.com/dtemp/archive/2004/08/17/215764.aspx

Bhaskar
+1  A: 

The App.config if for the design time. The real .config will be placed by compiler in the bin\Release\ or bin\Debug depending on the build mode you used. When you install your service using sc.exe or InstallUtil.exe, those tools expect you to have all service files to be in installation directory (directory of your main executable that you pass to those tools). Any change to your App.config will not be reflected in .exe.config until you build your Windows service project. If you need to create installer for your service, the setup project is supposed to deal with those things automagically but very often messes this and other things up. So, if you need an installer, use the http://installer.codeeffects.com or similar services to it. I don't known any free installer-building services, though, but this one is new and relatively cheap. I hope this helps :)

Jane
So I guess my question is, if i do not want to redeploy the service, in which config file do I change a setting?
In your <servicename>.exe.config that is in the installation folder of your service
Jane
Correction: if you need to change anything in the .config file of some installed and running service you'd have to stop the service first (in Services snap-in, for example), make changes to the <servicename>.exe.config file that is in the installation directory, then start the service again.
Jane
A: 

App.config is used as a template to create .exe.config and .vshost.exe.config when one does not exist. If it does exist, then visual studio does not overwrite it when you recompile. You can tell vstudio to overwrite it if you want by changing the app.config's properties in vstudio.

.vshost.exe.config is used (unless you tell it otherwise) during debugging.

.exe.config is used when you are not running the debugger.

Where you make the change depends on what environment you want the change reflected in.

Mystere Man