如何獲得代碼所在的程序集的路徑?是否有方法獲取當(dāng)前代碼所在的程序集的路徑?我不想要調(diào)用程序集的路徑,而只是包含代碼的路徑?;旧希业膯卧獪y試需要讀取一些相對(duì)于DLL的XML測試文件。無論測試DLL是從TestDriven.NET、MbUnit GUI還是其他地方運(yùn)行,我都希望路徑始終正確解析。編輯人們似乎誤解了我的要求。我的測試庫位于C:\projects\myapplication\daotests\bin\Debug\daotests.dll我想走這條路:C:\Projects\myapplication\daotest\bin\Debug\到目前為止,當(dāng)我從MbUnit Gui跑出來時(shí),這三個(gè)建議都讓我失望了:Environment.CurrentDirectory施予C:\程序文件\MbUnitSystem.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location施予C:\Document and Settings\George\LocalSettings\temp\.\DaoTests.dllSystem.Reflection.Assembly.GetExecutingAssembly().Location與前一個(gè)相同。
3 回答

jeck貓
TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
public static string AssemblyDirectory{ get { string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path); }}
Assembly.Location
CodeBase
UriBuild.UnescapeDataString
File://
GetDirectoryName
- 3 回答
- 0 關(guān)注
- 842 瀏覽
添加回答
舉報(bào)
0/150
提交
取消