有没有办法获得当前代码所在的程序集的路径?我不想要调用程序集的路径,只是包含代码的路径。
基本上我的单元测试需要读取一些相对于dll的xml测试文件。我希望路径始终正确解析,无论测试dll是从TestDriven.NET,MbUnit GUI还是其他的运行。
PS:人们似乎误解了我的要求。
我的测试库位置
C:\项目\ MyApplication的\ daotests \ BIN \调试\ daotests.dll
我想得到这个路径:
C:\项目\ MyApplication的\ daotests \ BIN \调试\
当我从MbUnit Gui运行时,到目前为止的三个建议都失败了:
Environment.CurrentDirectory
给出c:\ Program Files \ MbUnit
System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location
给出C:\ Documents and Settings \ george \ Local Settings \ Temp \ .... \ DaoTests.dll
System.Reflection.Assembly.GetExecutingAssembly().Location
给出了与前面相同的内容。
相似问题