0

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:

Could not load file or assembly 'Microsoft.Build.Framework'(VS 2017)

I've tried restarting Visual Studio, and even turning my computer off and on again. I've commented out the assembly lines in the web.config file shown above. I went into Nuget package manager and added Microsoft.Build.Framework to see if this would help (it didn't).

Here's what the project references look like:

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?

Andy Brown
  • 5,309
  • 4
  • 34
  • 39
  • I assume you done a clean project? (then shut down vs) and delete everything in the bin folder. You not mentioned if this is a asp.net web site, or a asp.net web site application? Regardless, try a clean, and then a re-build all. Also, check the project references page - see if any references are missing. – Albert D. Kallal Jan 02 '23 at 17:52
  • It's an ASP.NET website. I'd dearly love to rewrite it in MVC, but there's just too much legacy code. I don't have a clean project option (though I have rebuilt the solution - many times). I've added the references diagram to the initial question above. – Andy Brown Jan 03 '23 at 09:39
  • I deleted the contents of the bin folder, which added another error message about not being able to find a licenses file. I restored the files and then deleted everything apart from App_Licences.dll, which solved this problem and just showed my original error message. – Andy Brown Jan 03 '23 at 09:46

1 Answers1

1

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.

Someone also mentioned this page, which gives a good summary of the opacity of the build process:

How do references work in ASP.NET WebForms websites (not web applications)?

Andy Brown
  • 5,309
  • 4
  • 34
  • 39