DeploymentItem behaving differently in VS2010 and VS2012

断了今生、忘了曾经 提交于 2019-12-03 12:30:39

If you create a test settings file in your solution, enable deployment in it (by default deployment is off in the test settings) and select it in the test explorer (Test -> Test Settings -> Select test settings file), then it should work without changing the code as well.

After installing vs2012 and .net 4.5, looks like the deploymentitemattribute is out of sync with where it moves the files and where the executable looks for the files during execution of tests.

Cheap workaround:

  1. Leave the deploymentitemattribute path as-is
  2. See where the file is being moved to
  3. Change the test code to look in that location

Before this upgrade mstest was smart enough to find deployment items even if they were moved to a sub directory in the bin directory. Seems this is no longer the case.

So before the upgrade a line of your unit test code might look like this...

FileInfo fi = new FileInfo("temp.txt");

After the upgrade a line of your unit test code might look like this...

FileInfo fi = new FileInfo("\SubDir\SubDir2\models\temp.txt");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!