Jul 27

Resolved: The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly

Resolved: The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly

I recently have been working on an ASP.Net application and at some point I started to get build errors that although they were not stopping the build and allowed me to continue with the application’s execution, they were starting to get quite annoying.

This is a sample of the error message that tormented me for ages but because it wasn’t a show stopper I left it there for almost a week:

The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be
loaded from the assembly …\packages\Microsoft.Net.Compilers.1.0.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly ‘file:///…\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll’ or one of its dependencies. The system cannot find the file specified. 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.

Thankfully the solution was a simple one. If you take a look at the file in reference it points you to a packages location. It turns out that NuGet packages were committed to the repository and are breaking everything. To resolve this, you simply need to delete that packages folder (usually under <project name> \ <project name> \ packages.) I am afraid of deleting anything, so I went ahead and simply renamed the folder packages.broken and after that proceeded to build all again. The nice thing is that NuGet fetches the packages automatically on build so the folder got repopulated, nothing broke and my error was gone! After that I proceeded to delete the packages.broken folder and move on with my life.

The solution recap:

  1. Locate you project’s packages folder
  2. Delete the folder
  3. Rebuild your project
  4. You’re done!


1 comment

  1. Still does not work

Leave a Reply

%d bloggers like this: