Since a week or so, one project in a solution I have (Visual Studio 2022 Enterprise) has started to fail after changing Visual Studio version from Pro to Enterprise. I don't imagine this in itself affects NCrunch, but I had to reinstall both VS and NCrunch and maybe som new SDK or whatever was added or uppdated in the process. Anyway, the NCrunch build fails with this error:
Quote:..\..\..\..\Program Files\dotnet\sdk\7.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets (266, 5): The "ResolvePackageAssets" task failed unexpectedly.
System.InvalidCastException: [A]NuGet.ProjectModel.LockFile cannot be cast to [B]NuGet.ProjectModel.LockFile. Type A originates from 'NuGet.ProjectModel, Version=6.3.2.9, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadFrom' at location 'C:\Program Files\dotnet\sdk\6.0.406\Sdks\Microsoft.NET.Sdk\tools\net472\NuGet.ProjectModel.dll'. Type B originates from 'NuGet.ProjectModel, Version=6.5.0.136, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'LoadFrom' at location 'C:\Program Files\dotnet\sdk\7.0.200\Sdks\Microsoft.NET.Sdk\tools\net472\NuGet.ProjectModel.dll'.
at Microsoft.NET.Build.Tasks.LockFileCache.GetLockFile(String path)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
All other building attempts (DevOps, local etc.) work fine - it's only the NCrunch build that fails.
I have a global.json file that specifies the SDK to be 6.0.100. Allowing roll-forward or completely removing the global.json file makes everything compile with NCrunch again. There's nothing in the solution itself, as far as I can tell that targets the 7.0.200 SDK version. In fact, originally the latest SDK available in my system was v.7.0.102, and the error message was reflecting this. After installing the latest SDK version, the error message followed to reflect this change as well.
Hence, I gather "something" is ignoring the global.json resolving the latest available SDK in the system, which happens to clash with the SDK 6 version specified in the global.json file.
This problem only occurs specifically in one project in the solution, that is an Azure Function project. All other projects are building just fine, in the same solution.
All projects in the solution are targeting dotnet 6.