views:

284

answers:

3

Can a component designer access and modify the app.config or web.config file of a project at design time? More specifically, is there some hosting service exposed by VS to do this 'the proper way' ? I know I can locate the .config file myself, open it and have my way with it as I please, but I want this to go through the VS sanctioned way, primarily because of source control integration concerns.

A: 

component designer?¿

do you mean programaticly? http://www.beansoftware.com/ASP.NET-Tutorials/Modify-Web.Config-Run-Time.aspx

gonxalo
I really mean component designer. My Q is not how to edit the config, but how to do it through a VS exposed service
Remus Rusanu
+2  A: 

VS can and will edit you web/app config for all sorts of reasons. Also, there are certain situations where VS tools will give you a GUI for sections of the file (Which im guessing is what you are after). But for the most part the "the proper way" as you say is to hand edit it.

It could also be likely that if your project is big enough you'll have CI concerns and roll outs to several servers, which would mean scripting the generation of sections of your config files.

One final thing that's worth saying is that you shouldn't be looking for an MS blessed approach to anything, you should take your needs and come up with the most pragmatic approach with all the facts at hand.

Owen
I'll second that. While Microsoft takes a good approach to many things. It's important to ask yourself. "Is this really a good idea?". But then again that's a good approach with anything you deal with.
Martin Murphy
+1  A: 

You can hook up an IEventBindingService (I linked to the .NET 2.0 version, there are 1.1, 3.0, and 3.5 versions too)

Excerpt from the page:

The event binding service provides a way to link an event handler with a component event from designer code.

You can put your custom app.config manipulating code into the event handler that you expose.

John Weldon
ty, I'll look into this. I'm not sure if it offers access to what I need though. My dilemma is twofold: one is 'how do I locate the app.config of the project hosting my component?' and second is 'once located, how do I modify the app.config w/o messing up any source-control (ie. do a 'checkout' if required)?', so I was looking for a service similar to IResourceService http://bit.ly/1D3ms, but for the .config files
Remus Rusanu
Got it. Makes sense. I would expect that you could work up something similar inside of your event handler? Good question!
John Weldon
I still have to investigate this, but I accepted your answer as the bounty was running out of time.
Remus Rusanu
Thanks Remus! :)
John Weldon