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'."
Asked Answered
K

9

32

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?

Kappenne answered 21/7, 2023 at 20:6 Comment(3)
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 there is a resolution to this issue.Kappenne
In my case updating the Visual Studio 2022 to Version 17.7.4 is solver the problem.Royalty
Solved by updating VS to the latest available version.Jacintajacinth
K
6

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.

Kappenne answered 21/7, 2023 at 21:26 Comment(0)
P
10

From Select the .NET version to use doc:

The SDK uses the latest installed version

SDK commands include dotnet new and dotnet 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.

Panamerican answered 21/7, 2023 at 20:20 Comment(8)
Thanks, after adding that to that global.json file to root of my project, it does generate an additional message message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy; but I, unfortunately still get the same error afterward.Kappenne
@TysonGibby try clean-rebuild. If it does not help - manually delete bin and obj folders and restart VS. Also try building with dotnet buildPanamerican
@TysonGibby also please share output of dotnet --list-sdks and dotnet --version. And update VS 2022 preview to latest (4th) version (and .NET 8 preview too - it is at 6th, if I remember correctly)Panamerican
Thanks again for your help. I have tried a clean rebuild and manually deleting the obj and bin folders as well as the vs folder, please excuse me for not having stated so. I have now also added the additional information you requested.Kappenne
@TysonGibby you are targeting net6.0 but do not have .NET 6 SDK installed - install it (the best option I would say). Or change version in global json to 7.0.0 or 7.0.306.Panamerican
Strange, I definitely did not uninstall it. Not sure how that would happened. Been using it for a long time now. And I have other projects that are .NET 6 that are unaffected. I did install the .NET 6 SDK again and I am still getting the same error.Kappenne
@TysonGibby can you post a minimal reproducible example? Also try rebooting =)Panamerican
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 again.Kappenne
K
6

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.

Kappenne answered 21/7, 2023 at 21:26 Comment(0)
S
4

To resolve issues of this kind:

  1. Install the latest dotnet sdk for the .NET version used in your project. This can be downloaded from here: https://dotnet.microsoft.com/en-us/download/visual-studio-sdks
  2. Update your visual studio by clicking Help -> Check for updates in Visual studio
  3. Restart your machine
  4. (Clean and) rebuild your project
Swiftlet answered 27/9, 2023 at 8:21 Comment(0)
S
3

I had the same issue after updating to VS 17.9.7 (which already is the latest version at the time of this answer).

The analyzer assembly 'C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CodeStyle.dll' references version '4.10.0.0' of the compiler, which is newer than the currently running version '4.9.0.0'.

I don't use a global.json and didn't want to specifically add one as a workaround. Uninstalling the SDK version 8.0.300 solved it in my case, since VS seemed to use the also installed version 8.0.205 and apparently didn't use the newer version.

Apparently this is a known issue, which mentions additional workarounds:

  • Update VS version to a supported version (didn't work in this case, because the latest version doesn't support it)

  • Use global.json to pin a specific SDK version (mentioned here in other answers)

  • Setting a build variable, which I have not tested:

    Set BuildWithNetFrameworkHostedCompiler=true in your build. This configures the build to use a matching version of the compiler to your SDK version rather than to your VS version so in this case, it'll use a 4.10 version of Roslyn.

Sapid answered 21/5, 2024 at 8:31 Comment(1)
You're a BEAST @Sapid . I've tried everything above but didn't work. Your solution has solved my problem instantly. Appreciate it mate :)Coif
T
1

There are a few solutions here you can try:

  1. Update Visual Studio 2022 to 17.7.1
  2. Install the release version of the 7.0.400 SDK, not the preview one
  3. Make sure you're running the latest version of the Visual Studio 2022 Preview (17.8.0 Preview 1)
  4. Install the 7.0.307 SDK instead and target that with a global.json file

#4 is what worked for me on Azure DevOps Pipelines. Microsoft is supposed to be rolling out a fix there, but it isn't in Production yet.

Tegument answered 22/8, 2023 at 4:42 Comment(0)
M
1

This error was caused in our build pipelines because they contained a UseDotNet@2 task to target a specific version of a .net sdk, but the actual build was running a VSBuild@1. The VSBuild@1 task did not respect the dotnet CLI UseDotNet@2 task and was just compiling using the latest sdk on the build server which is .net 7 at current instead of .net 6 that was requested by the @UseDotNet@2 task. We switched the VSBuild@1 task to a DotNetCoreCLI@2 publish task and everything worked as expected.

Mauro answered 22/8, 2023 at 20:55 Comment(0)
B
1

I had the same issue with VS 2022 with .NET SDK 8.0.201. Adding sdk version 8.0.201 to global.json did not help. However, modified it to 8.0.101 and get it worked.

Bridges answered 7/3, 2024 at 3:55 Comment(0)
B
0

I had this issue on release version of VisualStudio 2022 and .NET 8 (v8.0.100-preview.6). To fix the issue i had to completely uninstall .NET 8, clean the project and restart Visual studio

Bonkers answered 1/8, 2023 at 17:8 Comment(1)
This is same answer has already been provided.Kappenne
A
0

I had similar issue with JetBrains Rider, 2024.1.2. It was caused by wrong MSBuild version configured in Settings > Build, Execution, Deployment > Toolset and Build.

The configured version was taken from ...\AppData\Local\JetBrains\Installations... After choosing my ...\dotnet\sdk... location the warning is gone.

Abc answered 7/6, 2024 at 9:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.