How to get Directory while running unit test

后端 未结 14 838
余生分开走
余生分开走 2021-02-02 05:07

Hi when running my unit test I\'m wanting to get the directory my project is running in to retrieve a file.

Say I have a Test project named MyProject. Test I run:

<
14条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 05:45

    Further to @abhilash's comment.

    This works in my EXE's, DLL's and when tested from a different UnitTest project in both Debug or Release modes:

    var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug", string.Empty));
    

提交回复
热议问题