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

Our local build script was using an older version of nuget.exe (4.7.1.5393) to restore NuGet packages. We started getting this error after updating to Visual Studio 2019 version 16.5.0. Updating to the latest version of nuget.exe (5.4.0.6315) fixed the issue for us.

nuget.exe can be downloaded here: https://www.nuget.org/downloads.


I believe I had the same issue as you did. I didn't save the whole error message, but my error message was

'Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

I am using Visual Studio 2017 and was trying to do Update-Database after Add-Migration.

To resolve the issue I closed Visual Studio and re-opened it, then re-ran Update-Database again.

This may or may not resolve your issue, but I thought I'd post just in case it would help.


The root cause of this problem comes from relative paths in the devenv.exe.config file to Microsoft.Build.Framework.dll (see xml tags).

Some Visual Studio Extensions are changing the current directory and makes relative paths invalid.

To fix it, open this file in the C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ directory. and replace all ..\..\MSBuild\15.0\Bin\ by C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\.