23

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?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Bryan
  • 3,421
  • 8
  • 37
  • 77
  • 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 https://www.visualstudio.com/en-us/get-started/build/hosted-agent-pool, the hosted build server is deployed with .NET 4.6 framework. – Cece Dong - MSFT Oct 16 '15 at 07:04

8 Answers8

35

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

Salman Lone
  • 1,526
  • 2
  • 22
  • 29
  • 1
    My solution is a mixed environment (slowly migrating my projects to the new csproj format but targeting the full framework for now). Removing the `Microsoft.Net.Compilers` package from my non-migrated project fixed the build issues. – Brian Surowiec Feb 20 '18 at 23:57
  • Thanks also worked for me by just below commands in package manager console **Uninstall-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform** AND **Uninstall-Package Microsoft.Net.Compilers** – MSTdev Mar 29 '19 at 21:50
11

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?

Community
  • 1
  • 1
Vicky - MSFT
  • 4,970
  • 1
  • 14
  • 22
8

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
pedrocha
  • 81
  • 1
  • 2
5

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

Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
Koder101
  • 844
  • 15
  • 28
4

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

3

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.

profescore
  • 31
  • 4
0

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

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