C# – The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly

azure-devopsazure-pipelinescvisual studio

I have a project that I have on TFS online. When Im trying to build the project, I get the following error:

Severity Code Description Project File Line
Error The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly C:\Users\Bryan\Source\Workspaces\TestProject\ContosoUniversity\packages\Microsoft.Net.Compilers.1.0.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'file:///C:\Users\Bryan\Source\Workspaces\TestProject\ContosoUniversity\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll' or one of its dependencies. Could not find the file. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. ContosoUniversity

Has this something to do with that Azure don't support ASP.NET 4.6?

Best Answer

Here was the fix for me. Using Nuget Package Manager, remove these two packages if referenced:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers

After that, run a rebuild. This ensured that the build was not trying to use a specific build exe. Click here for the Diff against previous revision