如何在解决方案中的多个项目之间共享2.0应用程序/用户设置? [英] How to share 2.0 app/user settings across multiple projects in a solution?

查看:151
本文介绍了如何在解决方案中的多个项目之间共享2.0应用程序/用户设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力了解app.config和user.config设置的工作方式(2.0方式),当我在一个项目中工作时,一切都很好.但是,我将需要一种在多个项目之间共享app.config和user.settings的方法.

例如,当我在"ProjectB"中时,我需要访问名称空间"ProjectA"设置...

ProjectA.Properties.Settings.Default.someVar;

问题在于,它一直在说由于无法访问而无法访问设置"它的保护级别.我不明白为什么我添加的ProjectA是ProjectB的项目依赖项,并添加了对ProjectA命名空间的引用,为什么我不能看到"设置?
 
感谢您的支持任何帮助.

I'm working on understanding how the app.config and user.config settings work (2.0 way), and everything is fine when I'm working in one project. I'm going to need a way, though, to share the app.config and user.settings across mulitple projects.

So for example when I'm in "ProjectB" I need to access the namespace "ProjectA" settings...

ProjectA.Properties.Settings.Default.someVar;

The problem is it keeps saying that it can't accesss Settings in accessible due to its protection level. I don't see why if I've added ProjectA is a project dependency for ProjectB and added the reference to the ProjectA namespace, why I can't 'see' the Settings?
 
Thanks for any help.

推荐答案

我所做的就是定义一个类项目",其中包含一个负责阅读该类的类.设置或提供对这些设置的访问权限.然后,您可以在其他项目中引用它,并按照您的解释使用负责通用设置"的类.

如果看不到资源,请确保该类的范围和方法您为访问此功能而创建的对象被设置为公开",否则您将在任何地方都看不到它们.

如果以上内容对您没有帮助,请提供一些示例代码,说明您在做什么,我相信我们可以立即使您的代码正常工作.

MVP Eduardo Sobrino
What I have done is to define a "Class Project" with a class that is in charge of reading the settings or provide the access to those settings where ever they are.  You then reference it in other projects and use the class in charge of your "common settings" as you have explained you did.

If you can't see the resource make sure that the class scope and methods that you created to access this functionality are set to "public" else you will not see those anywhere.

If the above don't help you, please supply some sample code of what you are doing and I bet we can get your code working in no time.

Eduardo Sobrino, MVP


这篇关于如何在解决方案中的多个项目之间共享2.0应用程序/用户设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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