Reputation: 2207
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)
Upvotes: 1
Views: 308
Reputation: 2729
@bhav I have found a solution to this , though officialy as per above answer it might be true, that Visual Studio 2022 is not suppoerted . the fix is available, found it after debugging into the source code etc. IF you are targetting .Net 8.0 , this error appears in all the builds.
The Solution lies here : Edit your .csproj Project file to look like this :
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> </PropertyGroup><PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> <ItemGroup> <Content Update="Properties\launchSettings.json"> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </Content> </ItemGroup> <PropertyGroup> <GenerateRazorAssemblyInfo>false</GenerateRazorAssemblyInfo> </PropertyGroup> </Project>
The main change above is the line which says
<PropertyGroup> <GenerateRazorAssemblyInfo>false</GenerateRazorAssemblyInfo> </PropertyGroup>
The optional change is this line
<PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup>
Try this and let me know @Bhav and @Joel Coehoorn
Upvotes: 0
Reputation: 416049
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.
Upvotes: 1