olduncleamos said:
I am trying to share one config file between multiple console apps. Is
there anyway I can set the config file name for the current
application?
Thanks in advance.
Hi Amos,
You can't specify configuration name like you can do with the output name of
the assembly, but you can create your own configuration file, name it
whatever you want and load it with . The code below demonstrates how to do
this. Config.file was originally a regular app.config file which was renamed
and copied to another folder.
C:\config.file
---
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Key" value ="Hello World"/>
</appSettings>
</configuration>
class Program
{
static void Main(string[] args)
{
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"C:\Config.file";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(map,
ConfigurationUserLevel.None);
Console.WriteLine(config.AppSettings.Settings["Key"].Value);
}
}
Using this method you will probably lose all type safety benefits gained
through a Settings file though. There may be ways to tell a Settings file
that the underlying configuration file is not the application configuration
file, but I am not aware of this possibility.