简体   繁体   English

System.CurrentDomain.AppDomain.BaseDirectory和Directory.GetCurrentDirectory()之间的C#差异

[英]C#-Difference between System.CurrentDomain.AppDomain.BaseDirectory and Directory.GetCurrentDirectory()

Can anyone tell me what's the difference between System.CurrentDomain.AppDomain.BaseDirectory and Directory.GetCurrentDirectory() in C#, please?? 谁能告诉我C#中System.CurrentDomain.AppDomain.BaseDirectoryDirectory.GetCurrentDirectory()之间的区别是什么?

See AppDomain on MSDN and also Directory.GetCurrentDirectory() on MSDN . 请参阅MSDN上的AppDomain以及MSDN上的 Directory.GetCurrentDirectory()

According to this question the difference is that 根据这个问题 ,不同之处在于

System.AppDomain.CurrentDomain.BaseDirectory returns current directory, not executable location, ie when run from outlook (sent as a link to \\server\\folder\\file.exe it will set BaseDirectory to user documents instead executable location from Jakub Pawlinski whereas Directory.GetParent(Assembly.GetExecutingAssembly().Location) gets the parent folder of the current execting assembly. System.AppDomain.CurrentDomain.BaseDirectory返回当前目录,而不是可执行位置,即从outlook运行时(作为链接发送到\\ server \\ folder \\ file.exe,它将BaseDirectory设置为用户文档,而不是来自Jakub Pawlinski而不是Directory.GetParent(Assembly.GetExecutingAssembly().Location)可执行位置Directory.GetParent(Assembly.GetExecutingAssembly().Location)获取当前exulateing程序集的父文件夹。

So the code I'm using now is: 所以我现在使用的代码是:

string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
    string config = Path.Combine(Directory.GetParent(location).FullName, "Config.xml"));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GetFullPath(".") 和 Directory.GetCurrentDirectory() 有什么区别? - What's the difference between GetFullPath(".") and Directory.GetCurrentDirectory()? C#Directory.GetCurrentDirectory()返回带有NUnit的system32 - C# Directory.GetCurrentDirectory() returning system32 with NUnit Environment.CurrentDirectory 和 Directory.GetCurrentDirectory 有什么区别? - What is the difference between Environment.CurrentDirectory and Directory.GetCurrentDirectory? AppDomain.CurrentDomain.BaseDirectory 更改为错误的目录 - AppDomain.CurrentDomain.BaseDirectory changes to wrong directory AppDomain.CurrentDomain.BaseDirectory和Application.ExecutablePath在实践中有什么区别? - What's the difference between AppDomain.CurrentDomain.BaseDirectory and Application.ExecutablePath in practice? Directory.GetCurrentDirectory - Directory.GetCurrentDirectory 为什么System.AppDomain.CurrentDomain.BaseDirectory返回不同的结果? - Why does System.AppDomain.CurrentDomain.BaseDirectory return different results? C#Uri AppDomain.CurrentDomain.BaseDirectory相对路径 - C# Uri AppDomain.CurrentDomain.BaseDirectory relative path Directory.GetCurrentDirectory 在单元测试中抛出 System.IO.DirectoryNotFoundException - Directory.GetCurrentDirectory Throwing System.IO.DirectoryNotFoundException in unit tests Directory.GetCurrentDirectory()不能在linux上运行? - Directory.GetCurrentDirectory() not working on linux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM