I have an existing project with UnitTests. When I build the unittests on my laptop, Macbook M1, I get the following error:
Error NETSDK1005: Assets file 'project.assets.json' doesn't have a target for '.NETFramework,Version=v5.0'. Ensure that restore has run and that you have included 'net50' in the TargetFrameworks for your project. (NETSDK1005)
The UnitTest project target framework is .NET 5.0 and builds and runs on my collegues latops.
If I create a new .net5.0 console application, it builds and runs fine on my laptop. When I add the same console application to my existing solution, I also get the error. Also, in the existing solution, the Micorsoft.NETCore.App framework disappears magically when opening the frameworks folder.
If I update the project to .NET 6 or 7 I get the same error about .NET 6 or 7.
Any ideas what could cause this?
The Assets file doesn't have a target framework for '.NET Framework,Version=v5.0'
error usually happens when MSBuild on Mono is being used to restore a solution in Visual Studio for Mac, and when MSBuild cannot find any supported .NET SDKs.
MSBuild on Mono does not support .NET SDKs 6.0.300 so Visual Studio for Mac downgrades to the oldest supported .NET SDK. In your case, on an Apple Silicon, it would likely be the case that MSBuild on Mono downgrades to no .NET SDK since the .NET 5 x64 SDK would be installed into a /usr/local/share/dotnet/x64 directory and not used.
MSBuild on Mono being used can happen if the solution contains any classic projects, which are non-SDK style projects.
To fix this problem open the Solution Options dialog, select Build - General, and uncheck Build with MSBuild on Mono
. This will ensure the solution is restored with .NET not MSBuild on mono.
Classic projects will still be built with MSBuild on mono when this is unchecked. When it is checked the entire solution is restore and built with MSBuild on mono. This feature of using MSBuild mono was added to support classic Xamarin projects since using a mix of .NET and MSBuild can cause problems. One problem is with classic Xamarin.Forms projects which fail to build since the later .NET SDKs build the reference assemblies for the .NET Standard project into a folder that the classic MSBuild on mono is not expecting.