MSBuild issues after upgrade to VS 16.7.2

asked 2020-09-03T08:23:33.463+00:00
Jesper Eckerström Persson 1 Reputation point

After upgrading VS to 16.7.2 from 16.6.5, MSBuild stopped working. I've tried to solve this issue for many days now, removing/adding versions and paths from GAC, registry, env path, restarting, uninstalling, installing, old versions and new, and so on, and haven't been able to solve it.
The symptoms right now:
for a brand new class library project in VS2019 (downgraded back to 16.6.5), I'm getting this error on build:
The "NuGet.Build.Tasks.GetRestoreProjectStyleTask" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> 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.

For the project I'm currently working on (ASP.NET targeting 4.7.2):
The "NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> 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.

I'm also getting "The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)" for every single reference.

Microsoft Build
Microsoft Build
A Microsoft platform for building applications with Visual Studio and .NET on Windows.
367 questions
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2020-09-04T06:10:13.857+00:00
    Dylan Zhu-MSFT 6,346 Reputation points

    Hi JesperEckerstrmPersson,

    You could follow the steps below to install the dll into global assembly cache :

    1. Open Developer Command Prompt for Visual Studio 2019 as administrator
    2. Run this command: cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE
    3. Run this command : gacutil /i Path\Microsoft.Build.Utilities.v4.0.dll,( the dll locates in C:\Windows\WinSxS)

    Best Regards,
    Dylan

    --------------------------------------------------------------------------------------------------------------------------------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments