C#-System.CurrentDomain.AppDomain.BaseDirectory 和 Directory.GetCurrentDirectory() 之间的区别
C#-Difference between System.CurrentDomain.AppDomain.BaseDirectory and Directory.GetCurrentDirectory()
谁能告诉我在 C# 中 System.CurrentDomain.AppDomain.BaseDirectory
和 Directory.GetCurrentDirectory()
有什么区别??
参见 AppDomain on MSDN and also Directory.GetCurrentDirectory() on MSDN。
根据this question,区别在于
System.AppDomain.CurrentDomain.BaseDirectory returns current
directory, not executable location, i.e. 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.
所以我现在使用的代码是:
string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
string config = Path.Combine(Directory.GetParent(location).FullName, "Config.xml"));
}
谁能告诉我在 C# 中 System.CurrentDomain.AppDomain.BaseDirectory
和 Directory.GetCurrentDirectory()
有什么区别??
参见 AppDomain on MSDN and also Directory.GetCurrentDirectory() on MSDN。
根据this question,区别在于
System.AppDomain.CurrentDomain.BaseDirectory returns current directory, not executable location, i.e. 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.
所以我现在使用的代码是:
string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
string config = Path.Combine(Directory.GetParent(location).FullName, "Config.xml"));
}