Visual Studio 2010中的属性(Settings.Settings)问题 [英] Properties (Settings.Settings) question in Visual Studio 2010

查看:274
本文介绍了Visual Studio 2010中的属性(Settings.Settings)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的VS 2010解决方案中有2个项目(均使用C#),并且希望在一个项目中具有应用程序设置",并从另一个项目访问它.我一直在做一些阅读,这些属性似乎是特定于特定项目的.但是,是否有任何方法可以从其他项目访问这些项目之一的财产价值? (下面的示例).其次,将其设置在一个项目中,然后将该值自动复制到另一个项目上的相同属性名称中吗?

我查看了几个不同的选项,遇到了属性管理器,但这似乎仅用于C ++,并且如上所述,我正在使用C#.

在主项目(Project1)的属性(Settings.Settings)中:
名称:类型:范围:值:
Test1字符串应用程序PC1


我可以使用Properties.Settings.Default.Test1(或Project1.Properties.Settings.Default.Test1)从Project1中的任何类轻松访问这些值.但是,当我尝试从另一个项目(Project2)中的类访问此值时,它不允许我这样做,并说我需要在此第二个项目的属性"中对此进行专门设置​​.因此,我只想要一种从Project2访问此Test1值的方式(类似于从Project2中的类访问Project1.Properties.Settings.Default.Test1之类的方法,可以使用Project1的Program.cs中的get和set或其他方式.有关如何执行此操作的建议值得赞赏,并且一些代码示例将非常有用.

谢谢.

Hi,

I have 2 projects in my VS 2010 solution (both using C#), and would like to have Application Setting in one project and access it from the other project. I have been doing some reading on this, and these Properties seem to be specific to a specific project. However, is there any way of either accessing the property value of one of these projects from a different project? (example below). Second best to set it in one project and have that value copied across automatically to the same property name on the other project?

I looked at a few different options, and came across property manager, but that appears to be used for C++ only, and as above I am using C#.

In Properties (Settings.Settings) from the main project (Project1):
Name: Type: Scope: Value:
Test1 String Application PC1


I can access these values easily from any classes in Project1 by using Properties.Settings.Default.Test1 (or Project1.Properties.Settings.Default.Test1). However, when I try to access this value from classes in the other project (Project2), it won''t let me, and says that I need to have this specifically set in the Properties for this second project. So, I just want some way of accessing this Test1 value from Project2 (something like Project1.Properties.Settings.Default.Test1 from a class in Project2, either using get and set in Program.cs of Project1, or some other way. Any suggestions on how to do this appreciated, and some code examples would be great.

Thanks.

推荐答案

本文可能会有所帮助:

在应用程序之间共享用户设置 [
This article may help:

Share User Settings Between Applications[^]


这篇关于Visual Studio 2010中的属性(Settings.Settings)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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