Build/Test Issues

Generated csproj is missing assembly reference

Started by rvgolovin on 3,018 views

Hello,
My NCrunch build is failing with missing assembly reference error. VS builds the project fine. The original project has this reference in this way:

<Reference Include="WebApiThrottle">
<HintPath>E:\NuCache\WebApiThrottle\lib\net45\WebApiThrottle.dll</HintPath>
</Reference>

There are many references like this in the original project and all of them but this one are making into the generated project in the NCrunch working directory.
Missing this reference in the generated project breaks NCrunch build.

What could make this reference to be excluded from the generated project?

Edited

Hi, thanks for sharing this problem.

Generally, it's recommended to avoid absolute file path references like this one as it can cause problems with some things, like grid processing.

However, I've tried testing this with a simple scenario in which the assembly is stored on a different disk to the project file, and confirmed that NCrunch does still handle this scenario correctly by copying the file into the workspace and updating the reference in the generated file.

Is this file being referenced from inside a Nuget package directory that has been redirected to a different location? If so, there is a possible chance that NCrunch is considering the reference to actually be a Nuget package, in which case it would step away from trying to introduce the AssemblyReference inside the generated file because this is normally handled downstream by Nuget package references. If this is indeed the case, I recommend either replacing your Reference with a PackageReference or moving the file outside the Nuget package directory.
Thank you for the suggestion. If I place the reference in another folder it does indeed makes the build pass. However this is not an option for my build system.
I also can't add Package Reference to this project as this is prohibited by the build system. There are no Package References in this project.

The NuCache folder is the NuGet package cache folder with close to 2K packages in it. It's not a NuGet package install folder, but rather a separate cache that is shared by builds from different repositories.

This particular project has 25 references to other packages in this NuCache folder. Only one of them is not making it to the generated project.
I tried both relative and direct path in the reference. It did not make any difference.

Is there a way to turn this NuGet package smarts off for NCrunch?

I tried turning off "Auto-detect NuGet build dependencies", but it did not help.
I'm sorry, but I cannot think of a way to allow you to resolve this problem without changing your build system.

NCrunch sits on top of a very complex platform consisting of layers of interaction between Nuget and MSBuild. In broad terms, a reference to an assembly is either done via Nuget or it's done through a direct assembly reference. Somehow, you've managed to create a reference that is technically both things at the same time, and NCrunch does not have a way to handle such a situation.

If the reason you're not able to move this assembly is because of compatibility with builds outside of NCrunch, the best I can suggest would be to add an environment variable that is used to specify the location of the assembly. You can then set this to a different location under NCrunch using the Custom environment variables setting.

If you're using a system with a centralised cache of assembly references, many of which happen to also be Nuget packages, you could try splitting the centralised cache into two separate directories - one for Nuget package assemblies and one to contain non Nuget packages that are centrally referenced using AssembyReference. In this way, the assembly can stay located outside the configured Nuget package cache while still being centrally stored and addressed.
I worked around the problem for now by simply renaming the cache folder on my box. This is odd and does not ensure me some other project is not going to break in the similar way with new cache folder name. This build serves countless number of projects and is used by 2K+ developers. I'd like to get to the bottom of this issue if possible.

Here is more context. The cache folder has expanded NuGet packages in it and nothing else. This is how this build system consumes the NuGet packages.
Why some paths are ok and some not?
Why would NCrunch expects some assembly references would be taken care by Package Reference if none of the projects in the solution ever have Package References?
Any chance adding a feature to switch this NuGet reassignment off?

Can you try setting the NUGET_PACKAGES environment variable on your machine to a different path to see if this makes any difference? (You'll need to restart VS before this will take effect).

Post a reply

Log in to reply.