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

Notification

Icon
Error

Random build issues
willapp
#1 Posted : Wednesday, January 13, 2016 3:32:57 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/27/2012(UTC)
Posts: 15
Location: UK

Was thanked: 4 time(s) in 4 post(s)
I appreciate this needs some investigation but here goes:

I use NCrunch daily at work and it's fantastic. However on a daily basis I find myself having to disable/enable NCrunch due to it failing to build my solution. In this scenario NCrunch reports build errors (such as missing/unrecognised references) but when I click the link to the error, Visual Studio says it's fine and will happily build. I always try right-clicking the offending project and using the "Reload and rebuild selected component" option but this never resolves the problem. Disabling and re-enabling NCrunch *always* fixes it.

I think the most common scenario where this happens for me is when I leave a solution open in VS but use Git to checkout a different code branch. Visual Studio pops up the dialog telling me that it needs to reload one or more projects, I say Reload All, then once VS has done its stuff NCrunch will then fail to build. I do a manual build and Visual Studio tells me my solution builds successfully but NCrunch doesn't seem to try to build again automatically. Clicking the "Reload and rebuild selected component" causes some background activity but then still reports the same errors as the first time. I disable then re-enable NCrunch and everything is happy again.

Whilst this isn't the biggest pain in the world, it does take a couple of minutes to do this and as I switch branches often, the delay soon adds up.

This is quite a large solution (26 projects, 8 of which are unit tests). I'm running VS 2015 Pro Update 1, ReSharper Ultimate 10.0.2 and NCrunch version 2.19.0.4.

Any suggestions for a resolution would be great. I'm happy to do some diagnostics to help identify the cause.
1 user thanked willapp for this useful post.
AvantPrime on 3/16/2017(UTC)
Remco
#2 Posted : Wednesday, January 13, 2016 10:04:02 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, thanks for sharing this issue.

Switching branches is a very complex action as it causes a massive cascade of changes to be run through the system in rapid sequence. The engine does its best to track every individual change and respond to it, but there are some known issues that can cause desynchronisation, especially around rapid changes to project XML.

My general advice is to switch off NCrunch if you trigger a task that results in large scale source code changes (such as a Nuget update or VCS action). I appreciate that this is far from ideal as NCrunch can take a minute or more to initialise when being used on larger solutions.

With that said, getting NCrunch to handle situations like this is always a goal. Any more information you can give me on the change patterns that cause a desync will always be very welcome.

When you perform a branch switch (which I assume consistently recreates the problem for you?), do you wait for the VCS action to completely finish before asking VS to reload the projects?
willapp
#3 Posted : Wednesday, January 13, 2016 11:30:42 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/27/2012(UTC)
Posts: 15
Location: UK

Was thanked: 4 time(s) in 4 post(s)
Hi Remco,

The branch switch is always complete before I reload - I actually use Git command line and not the built-in VS tooling so when I do a checkout or merge I wait on the command line for it to finish before switching back to VS.

One suspicion I have that could be contributing to this is Nuget packages. Sometimes when checking out a different branch it will have a dependency on a different version or a new package and I'm not sure if the NCrunch build process is updating the Nuget packages when it runs in the background? I suspect it doesn't because when I see it fail to build, I then do a manual build and *then* I see VS download the missing packages.

However this can't be the only issue as I'm sure I've had the same problem on checkouts where the Nuget packages are already there.

I agree turning NCrunch off before switching does stop this happening, and generally that's what I do now, but it is frustrating to have to resort to this due to the delay in productivity it causes me.
Remco
#4 Posted : Thursday, January 14, 2016 1:42:05 AM(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)
willapp;8227 wrote:

One suspicion I have that could be contributing to this is Nuget packages. Sometimes when checking out a different branch it will have a dependency on a different version or a new package and I'm not sure if the NCrunch build process is updating the Nuget packages when it runs in the background? I suspect it doesn't because when I see it fail to build, I then do a manual build and *then* I see VS download the missing packages.


This will definitely create problems for you. NCrunch doesn't automatically restore Nuget packages as part of its build - for good reason. NCrunch only builds projects inside its workspaces, and as each workspace is effectively transient and may have many copies, this would result in NCrunch downloading the same packages multiple times unnecessarily. The engine did actually used to do this - it utterly annihilated performance.

willapp;8227 wrote:

However this can't be the only issue as I'm sure I've had the same problem on checkouts where the Nuget packages are already there.


I'm aware of an issue in which a missing assembly reference can cause a desync. The issue arises because NCrunch is dependent upon MSBuild to tell it about the assemblies being referenced by a project, and MSBuild won't report assembly references that don't exist - it simply ignores them. You'll find you notice this when attempting to build a project that has a missing assembly reference; the compile errors give you an unsure message of 'Perhaps you are missing an assembly reference?'. This is because MSBuild has simply dropped the missing reference from the parameters passed into the compiler, so the compiler isn't sure whether the referenced file is missing or the reference just doesn't exist at all.

So anyway, when MSBuild doesn't tell NCrunch about a missing reference, NCrunch simply assumes the reference doesn't exist. This prevents it from tracking the filespace where the referenced DLL should be, making NCrunch completely ignorant of the assembly when it is then added at a later time. The end result is:

1. You switch branches in your VCS.
2. The Nuget DLLs being referenced by the original code are removed. The code now references DLLs that don't exist.
3. NCrunch reloads the projects that have been changed and queries MSBuild to establish the list of references. The missing DLLS are not included in this list making NCrunch unaware of them.
4. You rebuild your solution in VS, and the referenced DLLs are restored by Nuget.
5. NCrunch isn't aware that the references now exist and needs to reload the projects before it is aware of them.

This is the sole desync scenario that I'm aware of at the moment. It's possible that there are more, and if you can find them, please do share any more details you have. The above issue is extremely challenging to solve without breaking down vital abstractions and introducing other problems, but I'm certain that it will be giving you no end of trouble with your workflow.

Have you considered having separate cloned repositories in different areas of your disk to represent the different branches? If you're able to avoid needing to switch branches under your tooling, this could save considerable pain.
willapp
#5 Posted : Friday, January 15, 2016 9:47:35 PM(UTC)
Rank: Member

Groups: Registered
Joined: 7/27/2012(UTC)
Posts: 15
Location: UK

Was thanked: 4 time(s) in 4 post(s)
I don't really use separate folders for different branches, mainly because one of the great things I like about Git is its ability to switch branches in-place. I run web applications configured on IIS on my laptop and it would be a real pain having to re-point the sites at different folders each time I switch branch, not to mention that I'm a code reviewer on my team so end up using dozens of branches on a weekly basis, it just wouldn't be practical.

I appreciate this is a challenge and for now I can use the enable/disable fix but hopefully it's something you can solve in the long term, it will really make NCrunch a greater tool for me.
1 user thanked willapp for this useful post.
Remco on 1/15/2016(UTC)
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.047 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download