如何从控制台应用程序中访问 Properties 命名空间?
我正在尝试存储/检索存储在应用程序设置中的值。 从我的控制台应用程序中,我似乎无法访问 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,控制台应用程序中没有设置文件。 但是,您只需在解决方案资源管理器中右键单击您的项目,选择“属性”,然后在出现的窗口中单击“设置”选项卡即可添加一个。
应该有一个链接显示“单击此处创建默认设置文件”。 创建完成后,您就可以开始比赛了。
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.
2.然后你可以使用
.
2.then you cna use
.
所以.. 一旦我在保存属性的项目中创建了 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