.net-8.0visual-studio-mac

Unable to build a NET 8 solution in Visual Studio for Mac


I've received a Visual Studio solution that references NET 8 and I'm attempting to open it on Visual Studio for Mac.

I've installed NET 8 from the MS website and enabled the "Use the .NET 8 SDK if installed" setting in Visual Studio. However when I attempt to build the solution, I receive this error. Any ideas on how to resolve this so that I can build it? I've installed the latest version of System.CodeDom nuget but that doesn't resolve it.

Error:

/usr/local/share/dotnet/sdk/8.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.GenerateAssemblyInfo.targets(5,5): Error MSB4018: The "WriteCodeFragment" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'System.CodeDom, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
File name: 'System.CodeDom, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
 ---> System.IO.FileLoadException: Could not load file or assembly 'System.CodeDom, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>g__TryLoadAssembly|3(AssemblyName assemblyName)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>b__2(AssemblyLoadContext _, AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.Build.Tasks.WriteCodeFragment.GenerateCode(String& extension)
   at Microsoft.Build.Tasks.WriteCodeFragment.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) (MSB4018) (ClearBank.DeveloperTest)

Solution

  • Visual Studio for Mac was discontinued on August 30, 2023, 2 1/2 months before the release of .NET 8 in November of 2023. It was never fully updated to add complete .NET 8 support. The option you see was a preview, and it's not fully-baked for the final release.

    Additionally, the product is no longer supported at all as of August 30, 2024, including security updates, so you should strongly consider moving to a different environment. The official recommendation from Microsoft for Mac users would be VS Code, but I understand a lot of Mac people also use Rider.