44

A project I have been working on was upgraded from .NET Framework 4.6.2 to 4.7.2. On build, in a file that is not my code, I get the following error:

enter image description here

I also see the same error in the build tab of my project properties.

[2]

I'm at a loss- I've searched for the error and am coming up empty. Has anyone encountered and/or resolved this before?

6 Answers 6

79

Looks like after upgrading your build tool is changed from MSBUILD to Roslyn. Microsoft.Managed.Core.targets is Roslyn target file.

if you have following Nuget packages installed:

  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform

  • Microsoft.Net.Compilers

Then possibly it's causing the issue. Upgrade the Microsoft.CodeDom.Providers.DotNetCompilerPlatform to 2.x and remove the second one. That should fix the issue.

9
  • it was subtle but what you said helped me figured it out - Since the update to 4.7.2 was done while I was out, I actually only had 4.6.2 - and I let Visual Studio do the download of the SDK, but in the process, it must have tranformed the project builder to Roslyn while we use MSBuild (as you said). Reverting everything and loading it with 4.7.2 SDK already installed made the issue go away...
    – Matt
    Dec 11, 2019 at 1:01
  • 1
    Thanks!! In my case i had Microsoft.Net.Compilers 2.0, it seems tha version doesn't had conflicts, but after the package upgrade Microsoft.Net.Compilers 3.4 was installed this nightmare started. I just uninstalled Microsoft.Net.Compilers and now the project compiles ok :)
    – Jcis
    Dec 17, 2019 at 19:45
  • i accidentally downvoted. need to wait an hour to correct. this issue is related to VS 2017 v2019 too btw.
    – smoore4
    Mar 5, 2020 at 23:37
  • 3
    Removing Microsoft.Net.Compilers fixed it! +1 Mar 18, 2020 at 18:17
  • 1
    This error (in my comment above) was caused by trying to build a VS2019 project with VS2017 (in Azure DevOps). Using the right version of Visual Studio, in combination with your answer, resolved it. Apr 6, 2021 at 11:48
10

Ran into the same error - a compatibility issue between Microsoft.Net.Compilers 2.x (vs2017) and 3.x (vs2019) - downgrading from v3 to v2 fixed the issue specifically on our build agents which only had VS2017. v3 requires VS 2019 or later per roslyn-analyzers release spec.

Per the related error Method 'System.String.GetPathsOfAllDirectoriesAbove' not found - VS2017 would not even open the CSPROJ which was a clue about compatibility.

VS 2017 - CSPROJ Option to Install Missing Features for Microsoft.Net.Compilers v3

enter image description here

VS 2017 - Installing Missing Features

enter image description here

10

This happned to me when I updated Microsoft.Net.Compilers in an old project. Removing Microsoft.Net.Compilers completely, and then updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform resolved my problem.

4

This can also happen when trying to compile a VS2019 project with an older version of Visual Studio (e.g., on a build server or in Azure DevOps).

If, after applying the solution from answer https://stackoverflow.com/a/59276492/2279059, the error changes to

##[error]CSC(0,0): Error CS1617: Invalid option '8.0' for /langversion

then this is likely the case. The solution is then to build with the right version of Visual Studio (2019).

2

This error usually comes when you upgrade the below libraries by nuget

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Microsoft.Net.Compilers

Guys, If your project is not loading due to this error. just go to that project location by explorer and delete the obj folder manually.

Then right-click on the project and RELOAD AGAIN.

0

I had a similar issue, but I needed the Microsoft.Net.Compilers installed.
First, I removed the Microsoft.Net.Compilers, I had version 4.2.0 which is the latest for this date.

Removed it like that:

PM> Uninstall-Package Microsoft.Net.Compilers 

This should be enough but you can also unload the project and comment\delete the import tag in the csproj:

<!-- <Import something about Microsoft.Net.Compilers /> -->

This removed the error completely but I still needed to use Roslyn which required Microsoft.Net.Compilers. I looked at Microsoft documentation about Roslyn package.

I was using Visual Studio 2017 15.9 and they mentioned the correct version for my version:

2.10.0  Visual Studio 2017 version 15.9

I simply installed the compatible version and now I have it without any errors:

PM> NuGet\Install-Package Microsoft.Net.Compilers -Version 2.10.0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.