Build/Test Issues

The target "_SplitProjectReferencesByFileExistence" does not exist in the project.

Started by LatinProgrammer on 900 views

Hello,

We have a solution that is multi-targeted for different frameworks. NCrunch used to work with it and we switched to Visual Studio Live Testing. I switched back and the solution is failing on NCrunch with this error
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.queryValuesFromMSBuild()
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.processCallMethodMessage(CallMethodMessage callMethodMessage)
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.ProcessMessageReturningResult(Byte[] data)
at nCrunch.TaskRunner.Ipc.RemoteProxyCommunicator.readMessage(Byte[] returnedData)
at nCrunch.TaskRunner.Ipc.RemoteProxyCommunicator.Invoke(String methodName, Object[] args)
at nCrunch.Compiler.RemoteBuildRunnerProxy.AnalyseComponentBuild(ComponentLoadParameters parameters)
at nCrunch.Core.BuildManagement.BuildProcessLauncher.<>c__DisplayClass4_0.<AnalyseComponentBuildInExternalProcess>b__0(IRemoteBuildRunner remoteBuildRunner)
at nCrunch.Core.BuildManagement.BuildProcessLauncher.executeTaskUsingExternalProcess(Action`1 task, EffectiveProcessorArchitecture processorArchitecture, GridClientId client, BuildSystemParameters buildSystemParameters, IList`1 customEnvironmentVariables, Nullable`1 taskId, GridClientDescription clientDescription, DotNetCoreSdkVersion dotNetCoreSdkVersion)
at nCrunch.Core.BuildManagement.BuildProcessLauncher.AnalyseComponentBuildInExternalProcess(ComponentLoadParameters parameters, IList`1 customEnvironmentVariables)
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.analyseComponentBuild(EffectiveProcessorArchitecture buildProcessorArchitecture, String targetFrameworkForMSBuild)
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, IDEVersion ideVersion, BuildEngineId buildEngineId, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFrameworkForMsbuild, String visibleTargetFramework)


I reproduced the issue on a sample solution:
https://drive.google.com/file/d/1X5VvGW3OkDR-jsqggd0z2Pe7mnY-ZZwh/view?usp=sharing

You may need to open it twice. However, after doing so, Visual Studio builds and runs tests correctly. We also have multiple pipelines and msbuilds on our devops and we are able to correctly build the solution in the framework we choose.

The core issue seems to be that NCrunch doesn't work correctly with our "targets" file. We use it because we don't want to copy-and-paste common settings between projects. I also included Expand-CommonTargets.ps1 which replaces
<ImportGroup>
<Import Project="..\MultiTargetFile.targets" />
</ImportGroup>


With the actual contents of the file. After doing so, NCrunch works correctly.

However, the actual solution has many projects so this workaround is not ideal, and it would not be something that I would consider more of our devs doing. I tried a lot of workarounds and settings posted in the documentation and couldn't find something that works. I'm hoping this is something that you can fix in your end. Any help is appreciated.

-LP

Hi, thanks for sharing this issue along with the sample project (it's so much easier with a code sample to help understand what's happening).

For NCrunch to load a project, there is a critical property that must be present in the project, "TargetFrameworks".

This is because we need to know the target frameworks in advance of loading the project with MSBuild, so they need to be parsed out of the project file, which happens before any MSBuild evaluation or import logic can fire.

You can work around this though, without needing to change the the project file. In your NCrunch configuration for the project, go to 'Custom build properties' and set TargetFrameworks = net48;net8.0-windows

In this way, the loader will know what the frameworks are and won't need to parse them out of the file. NCrunch should then be able to load your projects as normal.
Thank you for the response. I added that custom build property and I was able to resolve the issue!

Post a reply

Log in to reply.