如何获取应用程序路径
我正在使用
string path = AppDomain.CurrentDomain.BaseDirectory;
来获取我的应用程序路径,但这给出了类似
C:\Projects\XYZ\ABC\bin\Debug
我不想要 bin\Debug 的信息。有什么方法可以实现此目的吗?
i am using
string path = AppDomain.CurrentDomain.BaseDirectory;
to get my application path ,but this gives something like
C:\Projects\XYZ\ABC\bin\Debug
i don't want bin\Debug .Is there any way to achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
AppDomain.CurrentDomain.BaseDirectory 属性获取程序集解析程序使用的基目录探测程序集。
所以它 100% 正常运行。如果您要构建应用程序,请将其剪切并粘贴到另一个文件夹或驱动器中的其他位置。这些更改将反映在该属性中。
另外,您提到您不想要这部分
bin\Debug
,所以您想要之前的部分?请具体说明。The AppDomain.CurrentDomain.BaseDirectory property gets the base directory that the assembly resolver uses to probe for assemblies.
So it's functioning 100% as it should. If you were to build your application, cut and paste it somewhere else in another folder or drive. Those changes would be reflected in this property.
Also, you mentioned that you do not want this part
bin\Debug
, so you want what's before that? Please be specific.得到你想要的:
to get what you want:
如果您想找出应用程序可执行路径(据我所知):
If you want to figure out your application executable path (as I understood):
老实说,这不是最好的做法,但这将提供您想要的:
To be honest, this is not the best pratice but this will give what you want:
您正在 IDE 中运行该程序,这就是您获得这种路径的原因。尝试构建应用程序并在 IDE 外部运行它 - 您会发现该方法工作正常。
编辑:您获得的是因为 IDE 运行位于 $PROJECT_DIR\bin\Debug 中的应用程序的调试版本。
You are running the program within IDE, and that's the reason why you get this kind of path. Try to build the app and run it outside IDE - you'll see that the method works correctly.
Edit: what you obtain is because IDE runs debug build of your app which is located in $PROJECT_DIR\bin\Debug.
我正在使用这个:
I am using this: