如何在Visual Studio中跨多个项目共享配置设置? [英] How can I share Configuration Settings across multiple projects in Visual Studio?

查看:442
本文介绍了如何在Visual Studio中跨多个项目共享配置设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定我知道这可能是一个设计问题,所以我也很乐意就此发表评论。

Ok I know this may be a design issue, so I would love to have remarks on that as well.

我有一个Visual Studio Web应用程序解决方案。我有三个项目作为UserInterface,BusinessLogic和DataAccess。

I have a Visual Studio web application solution. I have three projects as UserInterface, BusinessLogic and DataAccess.

我必须存储一些用户定义的设置,并在配置文件中创建了configSections。

I had to store some user defined settings and I created configSections in the config file.

我访问这些configSections通过继承自.NET的 ConfigurationSection 基类的类。

I access these configSections through classes which inherit from .NET's ConfigurationSection base class.

所以简单地说,每个项目我都有一个单独的configSection和对应的configSection我有一个类继承自 ConfigurationSection 访问配置部分设置。

So in short for every project I had a separate configSection and for that corresponding configSection I had a class in that project inheriting from ConfigurationSection to access the config section settings.

这个工作很棒。但如果有任何需要在多个项目中使用的设置,就会出现问题。所以如果我需要使用UserInterface项目configSection中定义的一个设置,那就说,BusinessLogic项目我必须在BusinessLogic的configSection中实际创建一个这个设置的副本。这样就可以在多个配置文件中复制相同的设置。

This works all sweet. But the problem arises if there is any setting which I need to use across multiple projects. So If I need to use a setting defined in UserInterface project configSection in, let say, BusinessLogic project I have to actually make a copy of that setting in the BusinessLogic's configSection. This ends up having the same setting copied across multiple configSections.

这不是有点太多了吗?

推荐答案

将共享配置设置放在一个单独的文件中,并使用这种技术:
http://blogs.msdn.com/jjameson/archive/2009/04/02/linked-files-in- visual-studio-solutions.aspx

Put shared config settings in a separate file and use this technique: http://blogs.msdn.com/jjameson/archive/2009/04/02/linked-files-in-visual-studio-solutions.aspx

这篇关于如何在Visual Studio中跨多个项目共享配置设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆