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

C#MsbuildMigrationVisual Studio-2017

C# Problem Overview


When I try running the command "update-database", I get this exception:

> Specify the '-Verbose' flag to view the SQL statements being applied > to the target database. System.IO.FileNotFoundException: 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. File name: > 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, > PublicKeyToken=b03f5f7f11d50a3a'
> > WRN: Assembly binding logging is turned OFF. To enable assembly bind > failure logging, set the registry value > [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There > is some performance penalty associated with assembly bind failure > logging. To turn this feature off, remove the registry value > [HKLM\Software\Microsoft\Fusion!EnableLog]. > > 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.`

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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>;.

Solution 3 - C#

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\.

Solution 4 - C#

I've found a workaround that seems to resolve the issue for good, at least on my environment running VS 2017 Professional 15.5.2 and Entity Framework 6.1.1.

Basically, install the DLL (with a few related ones) into the GAC (Global Assembly Cache) and the issue will go away.

Follow these steps:

  1. Close all running instances of Visual Studio 2017

  2. Launch the Visual Studio 2017 Developer Command Prompt

  3. Type the following commands (replace Professional with your edition, either Enterprise or Community, or adjust the path accordingly):

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Engine.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Conversion.Core.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll"

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll"
  1. Restart Visual Studio 2017

In essence, the GAC will (in most cases) be given priority when .NET is trying to load a DLL and the FileNotFoundException will go away as your DLL will now be resolved through the GAC.

Again, it works for me and it's simply a workaround, it won't solve the core issue itself but at least I don't have to restart VS all the time when trying to work with EF migrations, and that's good enough for me.

Solution 5 - C#

This worked for me - appears to be a non-support issue beginning in 2020.

In the Azure Build Pipeline > NuGet tool installer step, change Version of NuGet.exe to install to a newer version, like 5.4.0. Check versions at https://dist.nuget.org/tools.json.

Issue disappeared and now builds successfully.

Solution 6 - C#

My missing file or assembly version is different with the question.

I have this error when I tried to publish my ASP.net project

Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

I solved the problem by installing Microsoft Build Tools 2015

I think my problem caused by I publish project that was built with VS 2015 in VS 2017. Hope can help others that have same problem.

Solution 7 - C#

Just in case restarting Visual Studio does not work Go to Task Manager/ Process Explorer and skill VBCSCompiler.exe

enter image description here

Suggest using Process Explorer

Solution 8 - C#

In my case, something (maybe a NuGet-Update) did add an AssemblyBinding into the web.config-File:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" />
</dependentAssembly>

After removing that dependentAssemby-Entry, I could Publish the Project again.

Solution 9 - C#

This worked for me: The error occurs when I execute the nuget restore command. Nuget version 4.6.2. I have two ways to solve this problem.

Use Nuget 4.8.2 and higher. gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Build.Framework.dll

Solution 10 - C#

We had this issue, and here is what we needed to do in our case:

Problem was that we had a database command interceptor (IDbCommandInterceptor) configured that called HttpRuntime.Cache["somekey"], and for some reason migration commands failed to run because of this. After removing this depencency, all commands ran perfect. Maybe HttpRuntime weren't able to find the Build Framework dll?

So check the entire callstack when migration commands fails to see if you have a similar problem.

Solution 11 - C#

Closing and re-opening Visual Studio works like a charm!

Solution 12 - C#

After trying all of the above methods and more - running WCF app still failed for me. Error: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0..

> note: tried Restarting VS, PC, killing processes, cleaning up the VS caches, nuget caches, obj, bin, .vs, packages folders

What worked for me is removing the projects' *.csproj.user file.. Apparently it had some obsolete configuration in it. Lost 4 hours trying to figure it out..

Solution 13 - C#

Thanks to those who already posted. My situation was solved by a combination of the above. I have had several version of Visual Studio: 2015, 2017, 2019. At some point the version of MSBUILD went from 15.1 to 15.9, and I solved this issue by updating the C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe.config file to point to the 15.9 library. Here is an example of one of the entries:

<dependentAssembly>
      <assemblyIdentity name="Microsoft.Build.Utilities.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
      <bindingRedirect oldVersion="2.0.0.0-99.0.0.0" newVersion="15.9.0.0"/>
      <codeBase version="15.9.0.0" href="..\..\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll" />
</dependentAssembly>

Solution 14 - C#

I've faced with same issue when updated XCode/Mono components on macOS.

Solution is to update Visual Studio for Mac to latest version.

I think that issue cause in using new MSBuild tools from .NET Core 3.0 package which installed with new XCode/Mono version.

Solution 15 - C#

Using Visual Studio 2019 Community edition. I tried the other solutions without much luck, but after clearing me NuGet cache the issue seemed to be resolved. enter image description here

Solution 16 - C#

I did a restart, following which I found that the local web service I have been running was blocked by another process which had taken that port. I checked the process running and and killed the process using TCPView and all seemed to start working again.

Solution 17 - C#

I had this part in my web.config and simply removed it and then it start working :)

<compilation debug="true" targetFramework="4.5.2">
	<assemblies>
		<add assembly="Microsoft.Build.Framework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
	</assemblies>
</compilation>

Solution 18 - C#

Calling "MSBuildLocator.RegisterDefaults();" before DLLs are accessed worked for me.

Solution 19 - C#

Problem: Could not load file or assembly 'Microsoft.Build.Framework...

Solution: I had Microsoft.Build.Framework Nuget package referenced in my project and setting the reference for this NuGet package's Copy Local to True, issue was resolved for me.

Solution 20 - C#

In my Roslyn project, referencing the NuGet Package Microsoft.Build.Locator and calling MSBuildLocator.RegisterDefaults(); before creating the MSBuildWorkspace solved this problem.

Solution 21 - C#

I had to install visual studio with the .NET cross-platform development option. I did also get universal windows platform development too

https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2022

Solution 22 - C#

On macOS with .NET 6, I started seeing this error after upgrading form 6.0.1 to 6.0.2. The fix is to uninstall and reinstall dotnet-ef cli:

dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOleksii VorochenkoView Question on Stackoverflow
Solution 1 - C#EightgateView Answer on Stackoverflow
Solution 2 - C#Corey SmithView Answer on Stackoverflow
Solution 3 - C#Renaud BancelView Answer on Stackoverflow
Solution 4 - C#Mr LinguaView Answer on Stackoverflow
Solution 5 - C#Alfred WallaceView Answer on Stackoverflow
Solution 6 - C#V-SHYView Answer on Stackoverflow
Solution 7 - C#Arjun ShettyView Answer on Stackoverflow
Solution 8 - C#redM76View Answer on Stackoverflow
Solution 9 - C#Yovanny RodríguezView Answer on Stackoverflow
Solution 10 - C#Øyvind RaskView Answer on Stackoverflow
Solution 11 - C#Masoud DarvishianView Answer on Stackoverflow
Solution 12 - C#AlexView Answer on Stackoverflow
Solution 13 - C#ChilbertoView Answer on Stackoverflow
Solution 14 - C#picolinoView Answer on Stackoverflow
Solution 15 - C#JDandChipsView Answer on Stackoverflow
Solution 16 - C#SharpCView Answer on Stackoverflow
Solution 17 - C#hiFIView Answer on Stackoverflow
Solution 18 - C#David EhnisView Answer on Stackoverflow
Solution 19 - C#UsmanView Answer on Stackoverflow
Solution 20 - C#Tamás KovácsView Answer on Stackoverflow
Solution 21 - C#ASHView Answer on Stackoverflow
Solution 22 - C#Ssh QuackView Answer on Stackoverflow