Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Content files not copied
plillevold
#1 Posted : Monday, March 4, 2013 7:38:51 PM(UTC)
Rank: Member

Groups: Registered
Joined: 2/1/2013(UTC)
Posts: 11
Location: Norway

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Hi!

This may have been up for discussion already though I could not find any mention of it immediately.

The problem is this: I have a test project T referencing code project A and code project B. B contains a set of files marked as Content, some with "Copy to Output Directory" set to Always Copy and some set to Copy if Newer. Code in T and A both expects the content files from B to exist in the "current execution folder".

When building these projects with VS/MSBuild the files all get copied to the correct location, in T\bin\Debug. With NCrunch it does not, and my tests naturally fails.

I have tried setting the [Copy Referenced Assemblies..] to true on the test project, knowing that it probably will degrade performance. This does not seem to work though, the content files are still not copied to the T\bin\debug. I also tried the [Additional files to include] and included the project file for B. Still no luck.

I'm using NCrunch v1.44.0.11. Any ideas?

- Peter
Remco
#2 Posted : Monday, March 4, 2013 9:16:51 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Peter -

Support was added for including the copy of content files in the 1.43 release, so in theory this should work. In practice, I'm hoping you haven't been hit with a bug.

Does it make any difference if you turn on the 'Copy referenced assemblies to workspace' setting for ALL the projects in the solution, then reset the NCrunch engine?

If not, is there any chance you can put together a small reproduction of the problem? Issues such as this can sometimes be hard to pin down because of the amount of shadow copying involved.


Thanks!

Remco
plillevold
#3 Posted : Tuesday, March 5, 2013 8:56:26 AM(UTC)
Rank: Member

Groups: Registered
Joined: 2/1/2013(UTC)
Posts: 11
Location: Norway

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Tested some more and here's some observations:

Starting out without the [Copy ref...] and [Additional files...] settings set.

1. Resynchronized the project and seeing failing tests since the content files are not copied to the unit test workspace
2. Turned on [Copy referenced assemblies to workspace], upon which NCrunch starts doing some work and re-runs the tests
3. I'm now still seeing the same failing tests BUT content are now in the workspace
4. Clicking [Run all tests visible here] to re-queue the failing tests. They now go green
5. Final experiment: hit Resynchronize again. All tests still go green

I haven't been able to put together an isolated repro yet.

- Peter
Remco
#4 Posted : Tuesday, March 5, 2013 9:57:33 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Do the tests stay green now even if you restart the IDE? I'm wondering if perhaps NCrunch failed to correctly detect the content files that needed to be copied because MSBuild had already copied them with a prior build. I'll make a note to review how some of this code works to see if I can find any obvious holes. Please do let me know if you manage to create a small reproduction of the problem, or if you find clear steps to reproduce.


Cheers,

Remco
plillevold
#5 Posted : Monday, March 11, 2013 7:42:47 PM(UTC)
Rank: Member

Groups: Registered
Joined: 2/1/2013(UTC)
Posts: 11
Location: Norway

Thanks: 6 times
Was thanked: 1 time(s) in 1 post(s)
Whipped together a repro of the content problem: https://dl.dropbox.com/u...33210/ContentCrunch.zip

Update: added one more test illustrating that content files in subfolders also does not get copied.

And no, I guess this is not a repro of my problem, other than to illustrate that content files are not copied. If one turns on the [Copy referenced assemblies...] setting on the unit test project, the tests run just fine.

So my current conclusion is that my real project is doing something funcky to the content files, so that [Copy referenced assemblies...] option does not work as expected.

That said, would it be feasible to implement a [Copy content files from referenced projects] option? Or will the effect be the same as with the existing [Copy...] option?

- Peter
Remco
#6 Posted : Monday, March 11, 2013 9:11:18 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks Peter!

Because of the way NCrunch's build optimisations work, the 'Copy referenced assemblies to workspace' setting is needed for any project to copy assemblies or content files from a referenced project. This is behaviour by design - I'll quickly explain why this is the case.

Let's just say you have project A containing a content file MyResource.xml. This content file is set to be copied to the bin\debug directory of the project when it is built, and we'll just assume that some internal logic in Project A makes use of it.

We also have project B, which could be a unit test project referencing project A using a ProjectReference in the usual way. Project B executes (via test) code that runs within Project A making use of MyResource.xml.

Now lets just say we make a change to the 'MyResource.xml' file in project A. Because NCrunch is reliant on build logic to recopy (or potentially reprocess?) this file, NCrunch needs to rebuild project A. If project B required this file to exist in its bin\debug directory too, then it would also need to be rebuilt. Along with any other project that referenced either project A or project B. If project A sits at the bottom of a large dependency tree of 50 other projects, each of these projects would need to be rebuilt before any tests could be run.

NCrunch has no reliable way of knowing how depending projects make use of the projects they reference, so to prevent builds from running to the moon every time a change is made, it simply avoids copying the resource files and assemblies of referenced projects into the bin\debug of referencing projects. By turning on the 'Copy referenced assemblies to workspace' setting, you effectively tell NCrunch that you need these files to be copied, and so it won't execute shortened builds and you'll notice a bigger pause before your tests kick off and run.

I try to encourage people to design their code in such a way that they don't need to switch on the 'Copy referenced assemblies to workspace' setting. In this situation above, usually this would come down to how the MyResource.xml file is located within Project A. Code often makes the assumption that resource files are located adjacent to the runtime assemblies by relying on the current directory. If you avoid this and instead use the directory of the executing assembly, you can completely avoid the issue and you won't need to turn on the 'Copy referenced assemblies to workspace' setting. i.e. Path.GetDirectoryName(typeof(ATypeInMyAssembly).Assembly.Location) + "\MyResource.xml"

But where this isn't possible, switching on the copy referenced assemblies setting for all projects in the solution will allow your build process to work more or less as normal.

If you have this setting switched on and the files aren't copying, then this is definitely a bug that I'd much like to fix!


Cheers,

Remco
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.058 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download