Access App.Config Settings from Class Library Called through Unit Test Project

前端 未结 4 2053
暗喜
暗喜 2021-02-06 10:26

I have the following setup:

  • ASP.net 3.5 Web Site Project
  • C# Class Library with business logic
  • C# Class Library for unit testing

Th

4条回答
  •  盖世英雄少女心
    2021-02-06 10:45

    Try WebConfigurationManager.OpenWebConfiguration() method

    Configuration config = WebConfigurationManager.OpenWebConfiguration(@"x:\path\web.config");
                KeyValueConfigurationCollection appSettings = config.AppSettings.Settings;
                string connString = appSettings["connString"].Value;
    

提交回复
热议问题