C# 如何从控制台应用程序中访问 Properties 命名空间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/850416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I access the Properties namespace from within a console app?
提问by Nick
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!
谢谢!
采纳答案by womp
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.
应该有一个链接说“单击此处创建默认设置文件”。创建完成后,您就可以开始比赛了。
回答by Nick
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
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
-缺口