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.