Mono C# 获取应用程序路径
我正在寻找我的应用程序的目录,它似乎与常规 c# 不同?
如 Path.GetDirectoryName(Application.ExecutablePath)
不起作用。
I am looking to get the directory of my application it seems to be different from regular c#?
As in Path.GetDirectoryName(Application.ExecutablePath)
is not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种正确的跨平台解决方案是请
注意,
Environment.CurrentDirectory
和Assembly.GetExecutingAssembly().Location
(更准确地说,其目录)在语义上都是错误的,即使它们通常(但并非总是)是同一个目录:Assembly.GetExecutingAssembly()
,则会导致“/path/到/B.dll”。One correct and cross-platform solution would be
Note that both
Environment.CurrentDirectory
andAssembly.GetExecutingAssembly().Location
(more exactly, the directory thereof) are semantically wrong even though they are often - but not always - the same directory:Assembly.GetExecutingAssembly()
, it would result in "/path/to/B.dll".尝试Assembly.GetExecutingAssembly().Location
Try
Assembly.GetExecutingAssembly().Location