Running MsTest from the command line with a custom assembly base directory

前端 未结 2 1014
面向向阳花
面向向阳花 2021-01-18 05:37

I did quite a lot of research on the web and tried a few settings, but I couldn\'t reproduce the behavior of running MsTest in Visual Studio 2012 on the command line.

<
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 05:59

    This is due to an MSTest bug that sets the current directory to its own working directory, rather than the test project's bin (or deployment) folder. The workaround is to execute the following code in the constructor of your test class:

    Environment.CurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
    

    I got the idea from http://www.ademiller.com/blogs/tech/2008/01/gotchas-mstest-appdomain-changes-in-vs-2008/; however, note that, in my case at least, it required setting Environment.CurrentDirectory, rather than the reverse, as suggested in the article.

提交回复
热议问题