[英]DeploymentItem behaving differently in VS2010 and VS2012
I have a VS2010 solution that I'm trying to upgrade to VS2012. 我有一个VS2010解决方案,我正在尝试升级到VS2012。
I'm having a problem with the MSTest unit tests in VS2012. 我在VS2012中遇到了MSTest单元测试的问题。 All of the tests include DeploymentItem attributes on the test class.
所有测试都包括测试类上的DeploymentItem属性。
[TestClass]
[DeploymentItem(@"SubDir\SubDir2\models", "models")]
public class UnitTests
{ ... }
In 2010, it's correctly copying dependent files from the SolutionDirectory\\SubDir\\SubDir2\\models
directory. 在2010年,它正确地从
SolutionDirectory\\SubDir\\SubDir2\\models
目录中复制相关文件。
In 2012, it's attempting to copy from the directory where the tests are deployed SolutionDirectory\\UnitTests\\bin\\debug\\SubDir\\SubDir2\\models
在2012年,它试图从部署测试的目录中复制
SolutionDirectory\\UnitTests\\bin\\debug\\SubDir\\SubDir2\\models
I'm looking for a way to restore the old behavior. 我正在寻找一种方法来恢复旧的行为。
如果在解决方案中创建测试设置文件,请在其中启用部署(默认情况下在测试设置中关闭部署)并在测试资源管理器中选择它(测试 - >测试设置 - >选择测试设置文件),然后它应该在不改变代码的情况下工作。
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. 安装vs2012和.net 4.5之后,看起来deploymentitemattribute与移动文件的位置以及可执行文件在执行测试期间查找文件的位置不同步。
Cheap workaround: 廉价的解决方法:
Before this upgrade mstest was smart enough to find deployment items even if they were moved to a sub directory in the bin directory. 在此升级之前,mstest非常智能,即使将它们移动到bin目录中的子目录,也可以找到部署项。 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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.