3 回答

TA貢獻1827條經(jīng)驗 獲得超9個贊
System.Reflection.Assembly.GetExecutingAssembly()
.Location
1
System.IO.Path.GetDirectoryName
1根據(jù)Mindor先生的評論:
System.Reflection.Assembly.GetExecutingAssembly().Location
返回當前正在執(zhí)行的程序集所在的位置,在不執(zhí)行時,該位置可能是也可能不是程序集所在的位置。在影子復(fù)制程序集的情況下,您將在臨時目錄中獲得一個路徑。 System.Reflection.Assembly.GetExecutingAssembly().CodeBase
將返回程序集的“永久”路徑。

TA貢獻1995條經(jīng)驗 獲得超2個贊
您有兩個查找應(yīng)用程序目錄的選項,您選擇的目錄將取決于您的目的。
// to get the location the assembly is executing from
//(not necessarily where the it normally resides on disk)
// in the case of the using shadow copies, for instance in NUnit tests,
// this will be in a temp directory.
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
//To get the location the assembly normally resides on disk or the install directory
string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
//once you have the path you get the directory with:
var directory = System.IO.Path.GetDirectoryName(path);
- 3 回答
- 0 關(guān)注
- 972 瀏覽
添加回答
舉報