Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have multiple App.Config files in .NET console application?

I have a console application that has App.Confile file. Now the parameters that are environment specific are maintained here.

Now I am thinking to have multiple app.config files (like app.dev.config, app.test.config and app.prod.config) the way how we can have multiple Web.Config files.

In case of Web application, we can handle this and ConfigurationManager would pick respective Web.Config file.

In case of Console application, I am not sure. If Yes, how can we have multiple app.config files?

Appreciate your help.

Thanks

like image 612
Rita Avatar asked Dec 16 '10 18:12

Rita


People also ask

How many app config file in ASP.NET application?

These apps have two configuration files: a source configuration file, which is modified by the developer during development, and an output file that is distributed with the app.

Can we have multiple Web config files for an ASP.NET application?

Yes you can have two web. config files in application.

Can we have multiple configuration files in one project?

Yes, in large projects, having multiple Spring configurations increase maintainability and modularity. You can also upload one XML file that will contain all configs.


1 Answers

To follow on from Babak's answer, you could also separate parts of your config out into other config files by using the configSource attribute on any element which represents a ConfigurationSection, e.g.:

<appSettings configSource="appSettings.config" />

And in appSettings.config:

<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
    <add key="Blah" value="Nim nim nim" />
</appSettings>
like image 107
Matthew Abbott Avatar answered Oct 12 '22 18:10

Matthew Abbott