Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Config Files configSource outside the application directory folder

People also ask

Where are configuration files stored in your application?

These config files are typically placed under separate root directory than the rest of application code. For example, in case of Java they are typically under src/main/resources .

Where is .NET config file?

config, contains settings that apply to an entire computer. This file is located in the %runtime install path%\Config directory. Machine.

Where is config file in C#?

To store runtime settings, also known as initialization files, also known as application configuration files, and access them from Visual Studio . NET in C#, do the following: In Visual Studio . NET, chose File -> New -> File -> General -> Text file, and click "Open".


Another solution is simply to add the configuration file in all your projects as a link instead of actually copying the file to your projects. Then set the "Build Action" of the file to "Content" and "Copy to Output Directory" to "Copy if newer" and when you compile the project you will have the file in the output directory.

To add the file as a link in the "Add Existing Item" dialog box, there is an Add button with a dropdown. Choose "Add as link" from the dropdown on the Add button to complete the process.


Under appSettings you can use file= instead of configSource=


It seems that's that is the way it is. configSource must be in the same folder or deeper.

You could, although I'm not sure you should, use an NTFS hardlink. [mad grin]


Visual Studio 2015

If you are having this issue with Web.Config the accepted answer is correct but just to expand since this had me giving myself the face-palm:

When you add a .config file to your project using 'Add As Link' and then set the link's Copy property to 'Copy If Newer' or 'Copy Always', then the physical file will be copied to the /bin folder.

Thus, when you have a config section defined in Web.Config like this:

 <section name="mySpecialConfig" type="System.Configuration.AppSettingsSection" requirePermission="false" />

then you must define the related config element like this:

  <mySpecialConfig configSource="bin\MySpecialConfig.config">
  </mySpecialConfig>

such that the configSource points to the physical bin\MySpecialConfig.config file not to the link Also, note that the path is a relative physical path.

That may seem ridiculously obvious but if you haven't done this before the physical file is not yet in the \bin folder so it may not click right away.