我怎样才能获得真正的app.config路径 [英] How I can to get the real app.config path

查看:121
本文介绍了我怎样才能获得真正的app.config路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取app.config路径?,而不是myapplication.exe.config路径,我的项目根目录中的.config文件。



谢谢。

How I can to get the app.config path?, not myapplication.exe.config path, the .config file in the my project root.

Thanks.

推荐答案

您所说的配置文件,通过CLR的设计,与主可执行模块位于同一目录

您的应用程序的入口程序集,它是您在问题中描述的相同的架构的主题。



此外,你不要我们需要知道这些文件的位置,因为它不是为应用程序直接使用而设计的(但它可以用于配置应用程序可以使用的其他路径,因为这是配置的目的之一)。 br $> b $ b

请参阅:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa374182%28v=vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx [ ^ ]。



您总能找到配置文件,但我担心这会误用该功能。要找到完整路径,您可以这样做:

You are talking about the config file which is, by the design of CLR, is intended to be in the same directory as the main executable module
of the entry assembly of your application, and it is the subject of the same very schema you described in your question.

Moreover, you don't need to know the location of these file, as it is not designed to be used directly by the application (but it can be used to configure some other paths your application can use, as this is one of the purposes of configuration).

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa374182%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/2tw134k3.aspx[^].

You can always find the configuration file, but I'm afraid it would be a misuse of the feature. To find its full path, you can do this:
//C#:
string location = System.Reflection.Assembly.GetEntryAssembly().Location;
string configLocation = string.Format("{0}.config", location); // but why?





如果您还需要其他东西,您应该引入自己的配置文件,加密与否。特别是,使用数据合同非常方便:

http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ]。



-SA



If you need something else, you should probably introduce your own config file, encrypted or not. In particular, it's very convenient to use Data Contract:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

—SA


这篇关于我怎样才能获得真正的app.config路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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