Tim
Tim

Reputation: 99478

Is the arrangement of an application reading App.config specific to Visual Studio IDE and/or compiler?

I heard that for C# programs,

App.config —This file contains configuration settings that the application reads when it starts.

For applications compiled from C programs, they don't always read some files in a specific directory. Whether that happens is up to the applications.

Is the arrangement of an application reading App.config in a particular directory done by the compiler?

Is the arrangement specific to Visual Studio IDE or compiler?

If the application is compiled not within Visual Studio, will the arrangement still hold?

Thanks.

Upvotes: 1

Views: 28

Answers (1)

user1935361
user1935361

Reputation: 442

Good question. As I understand it, the reading of the configuration is handled by classes in the System.Configuration namespace, and by convention they search for the .config file in the same directory with the same name as the executable you are running. You can use System.Configuration's ConfigurationManager to open arbitrary .config files, but that's uncommon in my experience.

From the link:

Executable–hosted app.

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.

When you develop in Visual Studio, place the source configuration file for your app in the project directory and set its Copy To Output Directory property to Copy always or Copy if newer. The name of the configuration file is the name of the app with a .config extension. For example, an app called myApp.exe should have a source configuration file called myApp.exe.config.

Upvotes: 1

Related Questions