简体   繁体   English

DeploymentItem在VS2010和VS2012中的行为方式不同

[英]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: 廉价的解决方法:

  1. Leave the deploymentitemattribute path as-is 保留deploymentitemattribute路径
  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. 在此升级之前,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.

相关问题 如何在VS2010和VS2012中加载数据库项目? - How to load database project in VS2010 and VS2012? vs2012中的DeploymentItem不复制文件 - DeploymentItem in vs2012 Doesn’t copy files VS2012 OutOfMemoryException与VS2010没有异常的工作 - VS2012 OutOfMemoryException vs. VS2010 working w/o Exception AppFabric DataCacheFactory()初始化在VS2013中挂起,在VS2010和VS2012中正常工作 - AppFabric DataCacheFactory() initialization hangs in VS2013, works fine in VS2010 and VS2012 将项目从VS2010迁移到VS2012后无法继承接口 - can't inherit interface after migrating project from VS2010 to VS2012 从VS2010移至VS2012后,HTML渲染间歇性丢失内容 - After move from VS2010 to VS2012 HTML rendering is intermittently losing content VS2010和VS2012的两个C#项目文件在同一目录中 - Two C# project files for VS2010 and VS2012 in the same directory System.Linq Linq查询无法在VS2012中工作,但在VS2010中可以正常工作 - System.Linq Linq queries not working in VS2012 but works fine in VS2010 为什么数据驱动的单元测试在vs2012中在vs2010中正常工作时失败? - Why does data driven unit test fail in vs2012 when it worked fine in vs2010? 在项目开发过程中从VS2010升级到VS2012会有任何风险吗? - Is there any risk in upgrading from VS2010 to VS2012 in the middle of project development?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM