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!


You may also like...

3 Responses

  1. Still does not work

  2. Email Spoofed says:

    I concur. This did not fix the issue. Anyone else have any ideas?

    • Juan Carlos says:

      This is an old post so I am going to take a shot in the dark here. But you could remove the nupackage / dependency, delete the folder and then add it again. Also, maybe a related project is where the reference is at so check everything. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.