不能从程序集加载 BuildTasks.Csc 任务吗?

在这里问这样的问题,我感到很内疚,但我不知所措,希望能得到一些帮助。

像 Web 应用程序这样的概念验证是在一台个人电脑上构建的,然后放在一个回购单上,在另一台位于不同位置的个人电脑上下载。最初有一个自动构建功能,Azure 可以在签入时自动构建和发布,但是这个功能被移除了。事情一直在两端工作,直到其中一端包含了大量被排除在外的变化。现在我看到了以下错误:

“ Microsoft.CodeAnalysis.BuildTasks.Csc”任务不能是
从程序集加载的 ... 包 Microsoft.Net.Compilers.1.0.0 Build. . tools Microsoft.Build.Tasks. CodeAnalysis.dll。 无法加载文件或程序集 ’文件:///... 包 Microsoft. Net. Compilers. 1.0.0 tools Microsoft. Build. Tasks. CodeAnalysis.dll’ 或其依赖项之一。系统无法找到指定的文件。 确认声明正确,程序集 以及它的所有依赖项都是可用的,并且该任务包含一个 实现 Microsoft.Build.Framework.ITask 的 public 类。

对于从哪里开始寻找这个问题,有人有什么建议吗?

72520 次浏览

It turns out that NuGet packages were committed to the repository and breaking everything. Deleting the project\project\packages directory from the repo solved all build problems since NuGet fetches the packages automatically on build.

I got this error when I created a new branch for my project.

It drove me crazy for an hour. I tried most of the suggestions over the internet including the accepted answer to this question.

I then closed the project, opened it again, cleaned it and the error is gone. So this means this could be cache issue.

Anyways, just wanted to share.

Problem hides on TFS, you need to remove folder TestProject...\packages from TFS, check in, delete it from your local dir and build again. Worked!

I too tried the top answer with no luck so deleted the contents of my bin and packages dir, closed and re-opened VS and everything fine now.

Deleting the package and cleaning the solution solved it for me.

Deleting these three directories solves the problem.

  • /packages
  • /bin
  • /obj

NOTE: delete both /bin and /obj from all projects included in the solution (including Test projects).

I have tried all solutions described before, but none worked.

What solved it for me, was to update the Microsoft.Net.Compilers from the NuGet Package Manager

  • Right-click on your solution.
  • Go to Manage Nuget Packages.
  • Search for Microsoft.Net.Compilers.
  • Install or update on dependent projects as necessary.

Re-build, clean solution and restart Visual Studio worked for me.

In my case, the solution was:

Use Windows Explorer and navigate to the offending path: C:\MyApplication\Code\Main\ABCProject\ABCProject.UI\Bin

Right click on bin folder > select properties > Uncheck ReadOnly.

I just tried this on a clean install of a Windows 10 machine and the issue for me ended up being that I didn't have the .NET 3.5 framework installed. This stackoverflow question helps explain why.

Cannot build WIX project on windows 10

I delete all from packages folder and rebuild solution. It's worked for me.

In my case: this works for me.

It turns out my teammate had already started looking into Windows 10 development and had Microsoft Build Tools 2015 installed on his machine.

I installed the software from https://www.microsoft.com/en-us/download/details.aspx?id=48159 and the problem was solved.

Right Click on Solution. Go to Manage Nuget Packages for this Solution. Search forMicrosoft.Net.Compilers on Browse Section.

In my case, the solution was:

  1. Right Click on Solution.
  2. Go to Manage Nuget Packages for this Solution.
  3. Search for Microsoft.CodeDom.Providers.DotNetCompilerPlatform.
  4. Uninstall the searched Package.
  5. Restart the Visual Studio.

Deleting the bin folder worked for me

In vs2017 community there appeared a new item in the "build" menu. It disappeared after I used it and was called something like "Optimise project build packages". I clicked it and it fixed everything, just restart etc. I did it on two machines.

What it did was removed Microsoft.net.compilers 2.10.0 and replaced with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0.1

So there you go - more automagic...

My project was built with .Net Core 2.2 but I had .Net core 3.0 preview installed. I uninstalled .Net Core 3.0 from my system and went through all my class libraries, removing Microsoft.Net.Compilers 3.0, then rebuilt and it worked.

Use the below step:

1) Delete the package folder.
2) close the visual studio.
3) open the project and rebuild the project.

I moved my solution from one drive to another, and one of the files could not be copied because "in used", for which I click ignored, producing the error described in this post. Copying the missing file manually fixed it.

file: Microsoft.Build.Tasks.CodeAnalysis.dll Destination directory: packages\Microsoft.Net.Compilers.2.1.0\tools

For me I was trying to open a MVC5 project in VS 2013 and I was getting this error, Opened it in VS 2017 and up it worked just fine.