Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

build - Unnecessary project rebuilds when unit testing in Visual Studio

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

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".

  • 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 Visual Studio 2013 setting

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>Project 'ExampleProjectATest' is not up to date. Input file 'c:fsmysolution-devexampleprojectatestmyfolder amegeneratortest.cs' is modified after output file 'C:fsmysolution-devexampleprojectatestinReleaseexampleprojectatest.pdb'.

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

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:

Advanced Build Settings

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.

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.

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

Visual Studio Test Runner

Project 'ExampleProject' is not up to date. Input file 'C:fsmysolution-devexampleprojectaViewsSharedsomeview.cshtml' is modified after output file 'C:fsmysolution-devexampleprojectainexampleprojecta.pdb'.

ReSharper Test Runner

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

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#.

Update

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.

Update 2

Despite installing Update 4, nothing has changed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Project 'xyz' is not up to date. Project item 'c:mypathweb.config.dev' has 'Copy to Output Directory' attribute set to 'Copy always'.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...