Is there a way to get the path for the assembly in which the current code resides?
(有没有办法获取当前代码所在的程序集的路径?)
I do not want the path of the calling assembly, just the one containing the code. (我不希望调用程序集的路径,而只是包含代码的路径。)
Basically my unit test needs to read some xml test files which are located relative to the dll.
(基本上,我的单??元测试需要读取一些相对于dll的xml测试文件。)
I want the path to always resolve correctly regardless of whether the testing dll is run from TestDriven.NET, the MbUnit GUI or something else. (我希望该路径始终正确解析,而不管测试dll是从TestDriven.NET,MbUnit GUI还是其他版本运行。)
Edit : People seem to be misunderstanding what I'm asking.
(编辑 :人们似乎误解了我在问什么。)
My test library is located in say
(我的测试库位于)
C:\projects\myapplication\daotests\bin\Debug\daotests.dll
(C:\ projects \ myapplication \ daotests \ bin \ Debug \ daotests.dll)
and I would like to get this path:
(我想走这条路:)
C:\projects\myapplication\daotests\bin\Debug\
(C:\ projects \ myapplication \ daotests \ bin \ Debug \)
The three suggestions so far fail me when I run from the MbUnit Gui:
(当我从MbUnit Gui运行时,到目前为止,这三个建议使我失望:)
Environment.CurrentDirectory
gives c:\Program Files\MbUnit
(Environment.CurrentDirectory
给出c:\ Program Files \ MbUnit)
System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location
gives C:\Documents and Settings\george\Local Settings\Temp\ ....\DaoTests.dll
(System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location
给出C:\ Documents and Settings \ george \ Local Settings \ Temp \ .... \ DaoTests.dll)
System.Reflection.Assembly.GetExecutingAssembly().Location
gives the same as the previous.
(System.Reflection.Assembly.GetExecutingAssembly().Location
与上一个相同。)
ask by George Mauer translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…