Search code examples
c#dependencies.net-6.0visual-studio-2022.net-8.0

How to fix "The analyzer assembly references version '4.7.0.0' of the compiler, which is newer than the currently running version '4.6.0.0'."


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?


Solution

  • 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.