如何从控制台应用程序中访问 Properties 命名空间?

发布于 2024-07-19 07:19:20 字数 219 浏览 4 评论 0原文

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

string test = Properties.Settings.Default.MyString;

谢谢!

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?

string test = Properties.Settings.Default.MyString;

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别挽留 2024-07-26 07:19:20

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

应该有一个链接显示“单击此处创建默认设置文件”。 创建完成后,您就可以开始比赛了。

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.

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

椒妓 2024-07-26 07:19:20
  1. 确保您正在使用的类的命名空间是项目的默认命名空间。

2.然后你可以使用

string s = Properties.Settings.Default.THENAMEINSETTINGS;

.

输入图片此处描述

  1. Ensure the namespace of the class you're using is the default namespace of your project.

2.then you cna use

string s = Properties.Settings.Default.THENAMEINSETTINGS;

.

enter image description here

梦境 2024-07-26 07:19:20

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

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

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

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

-缺口

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:

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.

I hope this helps someone with a similar issue.

-Nick

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文