在 Visual Studio 中进行单元测试时会重建不必要的项目 [英] Unnecessary project rebuilds when unit testing in Visual Studio

查看:18
本文介绍了在 Visual Studio 中进行单元测试时会重建不必要的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题(和答案),但是尽管尝试了所有建议的选项,但我仍然卡住了.

I know about this question (and answers), but despite trying all the suggested options I am still stuck.

我有一个包含多个项目的解决方案,但对于这个特殊情况,假设我有我的 ExampleProjectA 和相应的单元测试项目 ExampleProjectATest.第一个添加为对测试项目的引用 - 不是通过 Visual Studio 的 "Project References" 而是作为到 DLL 的链接(类似于 "..Path$(Config)ExampleProjectA.dll") - 这是由于我们公司需要构建服务器,但是当我们还有"Project References"时也存在问题.

I have a solution with multiple projects, but for this particular case let's say I've got my ExampleProjectA and a corresponding unit test project ExampleProjectATest. The first one is added as a reference to the test project - not via Visual Studio's "Project References" but as a link to the DLL (something like "..Path$(Config)ExampleProjectA.dll") - this is due to build server requirements in our company, but the problem also existed when we still had "Project References".

  • 构建然后运行单个单元测试工作正常
  • 在单元测试中只改变一个字母,然后让测试运行总是会导致 ExampleProjectA 的重建,即使这不应该是必要的
  • ExampleProjectA 中的所有(只有几个)文件从始终复制"设置为如果更新则复制"在其各自的属性中没有帮助
  • 选中Tools =>下的复选框选项 =>项目和解决方案 =>构建运行(见下文)也没有改变任何
  • Building and then running a single unit test works fine
  • Changing just a single letter in a unit test and then letting the test run always results in a rebuild of ExampleProjectA, even though this shouldn't be necessary
  • Setting all (there were only a few) files in ExampleProjectA from "Copy always" to "Copy if newer" in their respective properties didn't help
  • Checking the checkbox under Tools => Options => Projects and Solutions => Build an Run (see below) also didn't change anything

为了查看是否有更多可用信息,我将构建输出设置更改为诊断.每次触发 ExampleProjectA 的重建时,输出窗口中的第一行是

To see if there was any more information available, I changed the build output settings to diagnostic. Each time a rebuild of ExampleProjectA is triggered, the first line in the output windows is

1>项目ExampleProjectATest"不是最新的.输入文件 'c: fsmysolution-devexampleprojectatestmyfolder amegeneratortest.cs' 在输出文件 'C: fsmysolution-devexampleprojectatestinReleaseexampleprojectatest.pdb' 后被修改.

1>Project 'ExampleProjectATest' is not up to date. Input file 'c: fsmysolution-devexampleprojectatestmyfolder amegeneratortest.cs' is modified after output file 'C: fsmysolution-devexampleprojectatestinReleaseexampleprojectatest.pdb'.

写入窗口的类名(例如namegeneratortest.cs)根据我更改的测试文件而变化.

The class name written to the window (e.g. namegeneratortest.cs) changes according to which test file I change.

不确定为什么会出现此消息,但下一步是禁用调试信息,如下所示 Project properties =>构建 =>高级 =>输出 =>调试信息 =>无:

Not sure why this message comes up, but the next step was to disable the debugging information as shown below under Project properties => Build => Advanced => Output => Debug Info => None:

还是一样,什么都没变.

Still the same, nothing's changed.

我尝试的另一件事是检查我的解决方案文件夹中包含的文件的时间戳(因为在某些情况下,用户有一个带有未来时间戳的文件 - 请参阅链接的帖子) - 无济于事.

Another thing I tried was to check the timestamps of the files contained in my solution folder (as there was a case where a user had a file with a future timestamp - see linked post) - to no avail.

我尝试的最后一件事是将 Configuration Manager 中的构建设置更改为不同的目标平台 - 有些设置不会让我成功构建解决方案,其他一些设置可以,但问题是描述一直存在,所以没有变化.

Last thing I tried was to change the build settings in the Configuration Manager to a different target platform - some settings wouldn't let me build the solution successfully, some other settings did, but the problem described persisted, so no change.

行为与 Visual Studio Test Runner 和 ReSharper 提供的行为相似(虽然不一样).

The behaviour is similar (not the same though) with both the Visual Studio Test Runner and the one provided by ReSharper.

Visual Studio 测试运行器

项目ExampleProject"不是最新的.输入文件 'C: fsmysolution-devexampleprojectaViewsSharedsomeview.cshtml' 在输出文件 'C: fsmysolution-devexampleprojectainexampleprojecta.pdb' 后被修改.

ReSharper 测试运行程序

项目ExampleProjectATest"不是最新的.输入文件 'c: fsmysolution-devexampleprojectatestmyfolder amegeneratortest.cs' 在输出文件 'C: fsmysolution-devexampleprojectatestinReleaseexampleprojectatest.pdb' 后被修改.

Project 'ExampleProjectATest' is not up to date. Input file 'c: fsmysolution-devexampleprojectatestmyfolder amegeneratortest.cs' is modified after output file 'C: fsmysolution-devexampleprojectatestinReleaseexampleprojectatest.pdb'.

我使用的是带有 ReSharper 8.2 和最新更新的 Visual Studio 2013 Premium Edition,我们的解决方案文件中的项目使用 C#.

I'm using Visual Studio 2013 Premium Edition with ReSharper 8.2 and the latest updates, the projects in our solution file are in C#.

更新

澄清一下 - 输出窗口中的第一行确实表明必须重新构建测试项目 - 这很好.但是,以下几行表明还必须重新构建 ExampleProjectA,这应该不是必需的.输出窗口的后续消息还显示必须重建其他项目(从 ExampleProjectA 引用.

To clarify - the first line in the output window does show that the test project has to be rebuilt - this is fine. The following lines, however, indicate that also ExampleProjectA has to be rebuilt, which shouldn't be necessary. Subsequent messages to the output window also show that other projects (referenced from ExampleProjectA have to be rebuilt.

更新 2

尽管安装了更新 4,但没有任何改变.

Despite installing Update 4, nothing has changed.

推荐答案

就我而言,解决方案是将配置文件的构建操作从始终复制"更改为如果更新则复制".花了一段时间才找到,因为我必须更改构建输出详细信息以获取有关哪个文件导致错误的详细信息,例如

For my case the solution was to change the build action of a config file from "Copy always" to "Copy if newer". It took a while to find as I had to change the build output details to get the details about which file was causing the error, e.g.

项目xyz"不是最新的.项目项c:mypathweb.config.dev"的复制到输出目录"属性设置为始终复制".

根据我的经验,多次构建时也可能会显示不同的文件名,因此请确保您拥有正确的文件名和/或如果问题仍然存在,请重新构建.

From my experience it can also happen that different file names are shown when building multiple times, so make sure you have the right one and / or build again if the problem persists.

另请参阅这个问题及其答案以查找更多信息.

Also have a look at this question and its answers to find some more information.

这篇关于在 Visual Studio 中进行单元测试时会重建不必要的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆