认识多(互操作性).NET解决方案的配置文件操作性、配置文件、解决方案、NET

2023-09-04 03:08:41 作者:⒈個亾、挺恏

考虑它有一个解决方案,4个项目:

Consider having a solutions with 4 projects in it:

1)ProjectSql:这是一个项目,其编制输出设置为,这是负责任的访问SQL Server数据库,并做一些事情的。最终库将能够提供的API,以便管理持久性的最终应用。

1) ProjectSql: This is a project, whose compilation output is set to Library, and this is responsible of accessing a SqlServer database and do something. The final library will be able to provide APIs in order to manage persistency for the final application.

2)ProjectWCF:这是一个项目,其编制输出设置为,这是负责定义服务合同,数据合同和服务的实现,让我应用托管服务。

2) ProjectWCF: This is a project, whose compilation output is set to Library, and this is responsible for defining service contracts, data contracts and service implementations to let my application host a service.

3)ProjectMiscellaneous:这是一个项目,其编制输出设置为,这是responsibe提供的API为其他的事情

3) ProjectMiscellaneous: This is a project, whose compilation output is set to Library, and this is responsibe to provide APIs for other things.

4)ProjectApp:这是一个项目,其编制输出设置为可执行文件(EXE),这是负责创建我的应用程序的业务逻辑。假设这是一个简单的控制台应用程序。该项目引用了所有其他的人。

4) ProjectApp: This is a project, whose compilation output is set to Executable (Exe), and this is responsible for creating the business logic of my application. Suppose this to be a simple Console application. This projects has references to all the other ones.

假设:假设每个项目都有其自己的配置文件。 ProjectSql,例如,定义了连接字符串到连接到数据库等等...

Assumption: Consider that every project has its own configuration file. ProjectSql, for example, defines connection strings to connect to a database and so on...

好了,我的问题是:考虑我的申请项目ProjectApp使用ProjectSql,好了,每次调用在ProjectSql一个操作需要连接到数据库,在这些电话中ProjectSql配置文件被引用获取连接字符串(一以 System.Configuration.ConfigurationManager简单的通话.... )。

Well, my problem is the following: consider that my application project ProjectApp uses ProjectSql, well, every call to a operation in ProjectSql needs to connect to database, in these calls the ProjectSql configuration file is referenced to get connection strings (a simple call to System.Configuration.ConfigurationManager....).

我想,如果我的ProjectApp,用自己的配置文件,将调用在ProjectSql操作,那么,该操作将引用到自己的配置文件。

I think that if my ProjectApp, with its own configuration file, makes a call to an operation in ProjectSql, then, that operation will reference to its own configuration file.

我的问题是:

我说的,是真的么???

What I said, is it true???

执行配置文件尊重项目层次结构。

Do configuration files respect the project hierarchy.

推荐答案

System.Configuration.ConfigurationManager可以告诉它读取配置文件。任何给定的应用程序通常有一个配置类似appname.exe.config或web.config文件。

System.Configuration.ConfigurationManager can be told which config file to read. Any given app will normally have one config like appname.exe.config or web.config.

因此​​,为了你的问题的答案是否定的。

So the answer to you question is NO.

当你调用System.Configuration.ConfigurationManager任何的类库,它是阅读ProjectApp.exe.config文件。

When you call System.Configuration.ConfigurationManager for any of the class libraries, it is the ProjectApp.exe.config file that is read.