I am writing a C# .NET 2.0 .dll that is a plug in to a Larger application. The visual studio project for my module has a app.config file which is copied to a MyProj.dll.con
You will need to load the x.dll.config
(with the Configuration API) yourself. All the automatic file handling (including the .Settings
) is all about machine.config/y.exe.config/user-settings.
To open a named config file:
System.Configuration.dll
assembly.System.Configuration
Create code like:
Configuration GetDllConfiguration(Assembly targetAsm) {
var configFile = targetAsm.Location + ".config";
var map = new ExeConfigurationFileMap {
ExeConfigFilename = configFile
};
return ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
}
1- open app.config file in visual studio
2- in the "configuration" tag add your configurations in tag "appSettings" as bellow:
<configuration>
<appSettings>
<add key="UserName" value="aaa"/>
<add key="Password" value="111"/>
</appSettings>
</configuration>
3- in your code c#
var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
string userName = appConfig.AppSettings.Settings["UserName"].Value;
string password = appConfig.AppSettings.Settings["Password"].Value;
and do not forgot to add this 2 usings for "ConfigurationManager" and for "Assembly"
if the System.Configuration does not show, you must add the reference "System.Configuration" in the References
4- you can update the configurations for the dll as bellow: