Using app.config with a class library

后端 未结 9 1349
忘掉有多难
忘掉有多难 2020-11-27 06:47

Frequently I need to create a .Net class library that requires an app.config for things such as database connection strings. However, these settings must be in the calling a

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 07:11

    If you're using NUnit, name your app.config file with the same name as your *.nunit project filename. So for example, if you called your project "ClassLibraryA.nunit", then name your class library configuration file "ClassLibraryA.config". They also need to reside in the same folder/directory. NUnit is actually using this as the main configuration file.

    If you have custom code, then you need to make sure your app.config (or web.config) is referencing the class library's app.config file. The application only cares about the root app.config or web.config. So you need to add a custom configuration section that points to the class library app.config.

提交回复
热议问题