23
votes

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?

8
Did you use hosted build server to build the project? Did you try to build the project on your local machine? Can you get a successful build locally? According to the "Software on the hosted build server" at website visualstudio.com/en-us/get-started/build/hosted-agent-pool, the hosted build server is deployed with .NET 4.6 framework.Cece Dong - MSFT

8 Answers

33
votes

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

11
votes

No, it is not related to Azure Web Apps doesn't support ASP.NET 4.6. Actually, you get this error message because NuGet packages are checked into version control.

So, you need to remove folder TestProject\ContosoUniversity\packages from TFS and build again. See: BuildTasks.Csc task could not be loaded from the assembly?

8
votes

I had the same problem sometime ago, to fix it:

  1. make sure your packages are not under source control
  2. Force restore all package, by deleting the package folder
  3. restart your visual studio
5
votes

In my case it got resolved by updating the below two Nuget packages to the latest version:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
4
votes

Delete the packages folder or its contents, clean, rebuild solves the problem for me.

3
votes

If you take a look at the file in reference it points you to a packages location. It turns out that NuGet packages is broken

To Resolve: you simply need to delete that packages folder (usually under project name \ project name \ packages.), then on build, Nuget will restore all the required packages.

0
votes

I needed to update all my Nuget packages on my development box, then check the project in to TFS again.

For added peace of mind, I deleted the packages folder in the Team City build folder.

0
votes

In case someone looks at this later on.

I was getting this issue only when building in DevOps.

But after manually deleting packages in my local build I started getting the same issue locally. After removing the apparently missing NuGets using the NuGet manager the issue resolved it's self both locally and on azure.

Not sure what caused it but might save someone a headache in the future.

I was using .net 4.7.2