查找控制台应用程序的根目录? [英] Finding the root directory of a console application?

查看:379
本文介绍了查找控制台应用程序的根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到我的c#控制台应用程序的根目录?

到目前为止,我已经尝试了一些建议,但是所有建议都返回可执行文件的位置,如下所示:
"C:\ AppName \ Source \ Client.AppName \ bin \ Release"

但是我想返回以下内容:
"C:\ AppName \ Source \ Client.AppName"

你知道我怎么能得到这个吗?

谢谢.

How can I find the root directory of my c# console application?

I''ve tried a few suggestions so far but all return the location of my executable like the following:
"C:\AppName\Source\Client.AppName\bin\Release"

However I want to return the following:
"C:\AppName\Source\Client.AppName"

Any idea how I can get this?

Thanks.

推荐答案

C:\ AppName \ Source \ Client.AppName \ bin \ Release

那是根目录.根目录是您的应用程序运行所在的位置.为什么需要从应用程序中了解项目所在的位置?

如果用于资源等.在VS中,选择它们,查看属性,然后将生成操作"设置为内容并复制新内容"作为复制到输出目录"选项.
C:\AppName\Source\Client.AppName\bin\Release

that is the root directory. the root being where your application runs from. Why do you need to get up to where the project is from within your application?

If it''s for resources etc. In VS, select them, look at the properties and set the Build Action to Content and Copy If Newer as the "Copy To Output Directory" option.


我认为您将必须自己删除"\bin\Release"子字符串,因为系统无法为您做出确定.例如,如果将可执行文件移动到"C:\Program Files\yourname\test",则exe和源代码之间没有链接.
I think you will have to remove the "\bin\Release" substring yourself as the system cannot make that determination for you. For example if you move your executable to "C:\Program Files\yourname\test" there is no link between the exe and the source code.


这篇关于查找控制台应用程序的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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