如何从控制台应用程序中访问“属性”命名空间?

时间:2021-10-02 23:44:52

I am trying to store/retrieve a value that is stored in the Application Settings. From within my console application I can not seem to access the Properties.Setting namespace. My web surfing has revealed that a little more work might be needed to do this from within a Console application. How does one do this?

我试图存储/检索存储在应用程序设置中的值。从我的控制台应用程序中,我似乎无法访问Properties.Setting命名空间。我的网上冲浪表明,在控制台应用程序中可能需要做更多的工作。怎么做到这一点?

string test = Properties.Settings.Default.MyString;

Thanks!

3 个解决方案

#1


By default there is no Settings file in a Console application. However, you can add one simply by right-clicking your project in the solution explorer, choosing "Properties" and then in the resulting window, click the "Settings" tab.

默认情况下,Console应用程序中没有设置文件。但是,您只需在解决方案资源管理器中右键单击项目,选择“属性”,然后在结果窗口中单击“设置”选项卡即可添加一个。

There should be a link saying "Click here to create a default settings file". Once that's created, you're off to the races.

应该有一个链接说“单击此处创建默认设置文件”。一旦创建,你就会参加比赛。

#2


  1. Ensure the namespace of the class you're using is the default namespace of your project.
  2. 确保您正在使用的类的名称空间是项目的默认名称空间。

2.then you cna use

那你用了

string s = Properties.Settings.Default.THENAMEINSETTINGS;

.

如何从控制台应用程序中访问“属性”命名空间?

#3


So.. Once I created my Settings.settings file in the project that is saving the property I ran into the issue of how to access these properties from another project in the same solution. The settings object is sealed so you have to use a little trickery to gain access to the property values in another project. I found my solution here:

所以..一旦我在保存属性的项目中创建了我的Settings.settings文件,我遇到了如何从同一解决方案中的另一个项目访问这些属性的问题。设置对象是密封的,因此您必须使用一点技巧来访问另一个项目中的属性值。我在这里找到了解决方案:

http://blog.decarufel.net/2007/10/getting-access-to-settings-in-another.html

Basically you create a link file to the Settings.Designer.cs file in the project where you are trying to retrieve the values.

基本上,您创建一个链接文件到您尝试检索值的项目中的Settings.Designer.cs文件。

I hope this helps someone with a similar issue.

我希望这可以帮助有类似问题的人。

-Nick

#1


By default there is no Settings file in a Console application. However, you can add one simply by right-clicking your project in the solution explorer, choosing "Properties" and then in the resulting window, click the "Settings" tab.

默认情况下,Console应用程序中没有设置文件。但是,您只需在解决方案资源管理器中右键单击项目,选择“属性”,然后在结果窗口中单击“设置”选项卡即可添加一个。

There should be a link saying "Click here to create a default settings file". Once that's created, you're off to the races.

应该有一个链接说“单击此处创建默认设置文件”。一旦创建,你就会参加比赛。

#2


  1. Ensure the namespace of the class you're using is the default namespace of your project.
  2. 确保您正在使用的类的名称空间是项目的默认名称空间。

2.then you cna use

那你用了

string s = Properties.Settings.Default.THENAMEINSETTINGS;

.

如何从控制台应用程序中访问“属性”命名空间?

#3


So.. Once I created my Settings.settings file in the project that is saving the property I ran into the issue of how to access these properties from another project in the same solution. The settings object is sealed so you have to use a little trickery to gain access to the property values in another project. I found my solution here:

所以..一旦我在保存属性的项目中创建了我的Settings.settings文件,我遇到了如何从同一解决方案中的另一个项目访问这些属性的问题。设置对象是密封的,因此您必须使用一点技巧来访问另一个项目中的属性值。我在这里找到了解决方案:

http://blog.decarufel.net/2007/10/getting-access-to-settings-in-another.html

Basically you create a link file to the Settings.Designer.cs file in the project where you are trying to retrieve the values.

基本上,您创建一个链接文件到您尝试检索值的项目中的Settings.Designer.cs文件。

I hope this helps someone with a similar issue.

我希望这可以帮助有类似问题的人。

-Nick