How to force an .EXE to use a different app.config file?

F

Frank Rizzo

How can I force an .EXE to use a different app.config file?
For instance, I have an MyApp.exe which by default uses MyApp.exe.config
file. Can I force it to use ThatApp.exe.config?

Thanks
 
D

Dmytro Lapshyn [MVP]

Hi Frank,

I think it's close to impossible - as far as I know, the algorithm for
loading <appname>.exe.config files is hard-coded and cannot be changed.
For more flexibility, consider using Microsoft Configuration Management
Application Block.
 
R

Reginald Blue

Frank said:
How can I force an .EXE to use a different app.config file?
For instance, I have an MyApp.exe which by default uses
MyApp.exe.config file. Can I force it to use ThatApp.exe.config?

You _could_ create a small .NET startup EXE which takes the other EXE and
your preferred config file as command line parameters... then create a new
app domain in the small config file, load the other EXE into the new app
domain, reset the config file to the preferred config file for that app
domain, then execute the Main command in the loaded EXE file.

But I wouldn't waste my time, personally, as I'm not sure what advantage
that would grant. Maybe you're trying to start multiple versions of an exe
each with a different configuration? You could have multiple directories,
each with a different config, but the same EXE, or you could pass the
alternate config file on the command line and parse it "manually" (which
really is easy since it's XML anway.)

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
 
F

Frank Rizzo

Dmytro said:
Hi Frank,

I think it's close to impossible - as far as I know, the algorithm for
loading <appname>.exe.config files is hard-coded and cannot be changed.
For more flexibility, consider using Microsoft Configuration Management
Application Block.

I think it is possible, given that NAnt build files provide an option to
run NUnit tests via a different .config file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top