I opened my Visual Studio 2022 project this morning and cannot get it to run any more due to the following error:
CS9057 The analyzer assembly 'C:\Program Files\dotnet\sdk\8.0.100-preview.6.23330.14\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll' references version '4.7.0.0' of the compiler, which is newer than the currently running version '4.6.0.0'."
I am currently using Microsoft Visual Studio Community 2022 (64-bit) Version 17.6.5
My project file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Analyzers" Version="6.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="6.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.16" />
<PackageReference Include="MudBlazor" Version="6.2.3" />
</ItemGroup>
</Project>
I did recently install the Microsoft Visual Studio Community 2022 (64-bit) Version 17.7.0 Preview 3.0
that includes the .NET 8 SDK
. This is what seems to be causing the analyzer reference conflict.
I have not been able to find documentation to aid me in changing my analyzer references back to the correct version and there does not seem to be any way to do it in the Nuget Package Manager
or the Reference Manager
.
My other .NET 6 projects work, just not this one.
I have tried cleaning the project and deleting the obj and bin folders and even deleting the vs folder.
output from dotnet --list-sdks
:
3.0.103 [C:\Program Files\dotnet\sdk] 3.1.426 [C:\Program Files\dotnet\sdk] 7.0.306 [C:\Program Files\dotnet\sdk] 7.0.400-preview.23330.10 [C:\Program Files\dotnet\sdk] 8.0.100-preview.6.23330.14 [C:\Program Files\dotnet\sdk]
Output from dotnet --version
:
8.0.100-preview.6.23330.14
How do I change the analyzer references back to .NET 6? or what is the best way to fix this problem?
From Select the .NET version to use doc:
The SDK uses the latest installed version
SDK commands include
dotnet new
anddotnet run
. The .NET CLI must choose an SDK version for every dotnet command. It uses the latest SDK installed on the machine by default, even if:
- The project targets an earlier version of the .NET runtime.
- The latest version of the .NET SDK is a preview version.
Try adding global.json file to the root of the project:
The global.json file allows you to define which .NET SDK version is used when you run .NET CLI commands. Selecting the .NET SDK version is independent from specifying the runtime version a project targets. The .NET SDK version indicates which version of the .NET CLI is used.
With something like:
{
"sdk": {
"version": "6.0.0",
"rollForward": "latestMinor"
}
}
Also updating .NET SDKs to latest versions (i.e. latest .NET 6 and .NET 8 in this case) and installing latest VS version (plus "the usual" - restart VS, reboot machine, delete bin/obj folders) can help.
Because of time constraints I ended up uninstalling the VS 2022 preview for .NET 8 and the .NET 8 SDK, and to fully get rid of the issue I needed to then uninstall the current .NET SDK and reinstall it. The project now builds and runs again.
We will install .NET 8 again at a later time after they have worked out these bugs.
UPDATE: I recently updated to the latest Visual Studio Release Version 17.8.0
with .NET 8.0 SDK v8.0.100
. The final release version.
This has fixed the problem for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With