Reading dll.config (not app.config!) from a plugin module

前端 未结 2 1380
不知归路
不知归路 2020-11-30 05:08

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

2条回答
  •  -上瘾入骨i
    2020-11-30 05:41

    1- open app.config file in visual studio

    2- in the "configuration" tag add your configurations in tag "appSettings" as bellow:

    
        
            
            
        
    
    

    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"

    • using System.Configuration;
    • using System.Reflection;

    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:

    • open the file "MyProj.dll.config"
    • then update your configurations

提交回复
热议问题