Home > Mobile >  Visual Studio 2022 - could not load file or assembly Microsoft.Build.Tasks.v4.0. The system cannot f
Visual Studio 2022 - could not load file or assembly Microsoft.Build.Tasks.v4.0. The system cannot f

Time:01-03

So I'm back from a nice Christmas break - and completely stymied. When I try to build my Visual Studio 2022 solution I get this message:

Build (web): Could not load file or assembly 'Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I also get this in VS 2019 too. My website is ASP.NET webforms - I've got two other MVC websites which build and run perfectly. Here is the relevant section of my web.config file:

<compilation debug="true" strict="true" explicit="true" batch="false" targetFramework="4.7.2">
      <assemblies>
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Printing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>

I've just spent 3 hours reading through blogs like this StackOverflow one:

enter image description here

I've had this sort of problem on numerous other occasions, and usually sorted it fairly quickly - but not this time. I know little about building projects - I just want Visual Studio to do it all for me!

Can any kind person help please?

CodePudding user response:

As the error said, Microsoft.Build.Tasks.v4.0 could not be found.

Have you tried adding this reference? instead of Microsoft.Build.Framework.

enter image description here

CodePudding user response:

So I've at least got this in a working state - here's an update for anyone else facing this nightmare (and who, like me, doesn't fully understand what building involves).

I still have the build error, but if I right-click on a .aspx file to view it in a browser this now works (before it gave a compilation error). To reach this state I removed any references to any Microsoft.Build libraries that I had set in Nuget. I don't know whether this helped or not!

Of course I can't debug (because this requires a build), so this is at best a temporary fix, but at least I can do some work on the website.

  • Related