Build/Test Issues

NCrunch cannot build dotnet 5 projects

Started by amo11 on 2,413 views

I am using the latest version of both Visual Studio 2019 (16.11.5) and 2022 (17.0.0) together with the latest version of NCrunch (4.11.0.2).

For solutions/projects targeting .NET Framework 4.8 everything works as expected. For solutions/projects targeting .Net 5 however, NCrunch cannot build any projects, and fails with the message

System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> nCrunch.Common.UserException: Errors occurred while trying to load the project file:
The target "_SplitProjectReferencesByFileExistence" does not exist in the project.
at nCrunch.Compiler.ComponentAnalysisContext.()
at nCrunch.Compiler.ComponentAnalysisContext.AnalyseComponentBuild()
at nCrunch.Compiler.RemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.(CallMethodMessage )
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.ProcessMessageReturningResult(Byte[] data)
at nCrunch.TaskRunner.Ipc.RemoteInstance.(Byte[] )
at nCrunch.TaskRunner.Ipc.RemoteInstance.Invoke(IMessage msg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at nCrunch.Compiler.IRemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
at nCrunch.Core.BuildManagement.BuildProcessLauncher..(IRemoteBuildRunner )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , FilePath , String , ExternalProcess )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , EffectiveProcessorArchitecture , GridClientId , BuildSystemParameters , IList`1 , Nullable`1 , GridAddress , DotNetCoreSdkVersion  )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.AnalyseComponentBuildInExternalProcess(ComponentLoadParameters parameters, IList`1 customEnvironmentVariables)
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.(EffectiveProcessorArchitecture , String )
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, VisualStudioVersion vsVersion, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFrameworkForMsbuild, String visibleTargetFramework)



This issue first occurred for me since a couple of months ago, after upgrading Visual Studio 2022 preview (I cannot remember which version unfortunately). Based on similar posts in the forum here I attempted to use global.json files to fix the problem without success.

All our .Net 5 projects build successfully via both Visual Studio (2019 and 2022), as well as via the command line. All tests run without problem from Visual Studio (again both 2019 and 2022) as well.

How can I find more information so this problem can be fixed? I am really missing NCrunch
Hi, thanks for sharing this problem.

This issue usually appears when the project is being pointed at an SDK installation path that is corrupt or doesn't exist. Could you check the installed SDKs inside "C:\Program Files\dotnet\sdk" to make sure they look to be intact? Sometimes we've seen issues like this reported when there is an empty SDK directory.

Can you also confirm whether you've upgraded your VS2022 to the RTM build? (This is relevant because of preview SDK search logic).
Hi - thanks for your reply.

I can confirm that I have the RTM version of Visual Studio 2022 installed (I did try to update directly from the preview version to the RTM version, but I wasn't sure that worked correctly so I ended up removing the preview version of Visual Studio 2022 and then installing the RTM version).

I took a closer look at the dotnet sdk's and runtimes that I had installed.

I found that one .net core 3 sdk had no files under it's folder (C:\program files\dotnet\sdk\3.1.0.120), and a number of .net 5 sdk's were not found under windows settings app list (i.e. the folder under C:\program files\dotnet\sdk had no corresponding entry in the app list maintained by windows).

I have removed everything except what is required by Visual Studio 2019 and 2022 (so now only .net sdk's 5.0.403 and 6.0.100 are installed).

Unfortunately I am still seeing the same problems with NCrunch - works with .Net framework 4.8, but fails on .Net 5 projects with exactly the same error as before.

What is the next step to try and fix this?



Could you try submitting a bug report after you experience the build failure? I might be able to glean some useful info from the log in the report.
Thanks for submitting the report.

The problem is caused by a couple of custom environment variables you have configured for NCrunch. They are pointing at an SDK install path that most likely doesn't exist:
DOTNET_MSBUILD_SDK_RESOLVER_SDKS_VER = 5.0.302
DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR = C:\Program Files\dotnet\sdk\5.0.302\Sdks

Removing these variables from your NCrunch settings should resolve the problem. Most likely you had them in place to work around known issues between NCrunch and the VS2022 preview builds.
Many thanks - I had completely forgotten about these env variables. Removing these variables fixed the problem.

As you thought, I had originally set them to work around the same issue with preview versions of Visual Studio 2022, and unfortunately they were a bit hard to spot in the NCrunch configuration.

I am so very happy to have NCrunch back now!

Post a reply

Log in to reply.