talbrecht;16672 wrote:
I've always thought that NCrunch enhances the code for testing with NCrunch somehow, e.g. for tracking code lines hit by tests. Therefore the added code must reference NCrunch and breaks your NetArchTest test code which looks at the referenced assemblies during test execution and allows dependencies to System.* only.
Thanks for taking the time you share your thoughts on this. I can provide some extra details about NCrunch's instrumentation in the hope this might help both you and others.
Just after NCrunch builds your assembly in its workspace using MSBuild, it will load the assembly into memory in binary form and will manipulate it, adding extra instructions to each method (instrumentation) to allow it to track code coverage, as well as a few other things.
You can examine this instrumentation using a disassembler like ILDASM, ILSpy, dnSpy, etc. You can find the instrumented assembly by right clicking on the project in the NCrunch Tests window, then choose Advanced->Browse to workspace.
The instrumentation consists of a series of calls to nCrunch.TestRuntime.dll. This is a relatively lightweight assembly and is the only assembly referenced by NCrunch's instrumentation. In turn, this assembly references nothing else outside of system libraries.
NCrunch normally installs this assembly into the GAC when you run the installer, but since .NET Core (and newer versions of .NET), the GAC is not in the runtime's search path. To compensate for this, NCrunch will copy nCrunch.TestRuntime.dll (or nCrunch.TestRuntime.DotNetCore.dll for .NET Core and .NET5+) into the build output directory of your test project. As such, it's collocated with your assembly and usually should resolve without problems.