dotnet ef throws Could not load file or assembly Microsoft.DotNet.Cli.Utils,
Steps to reproduce
- Followed instructions as per https://docs.efproject.net/en/latest/platforms/netcore/new-db-sqlite.html -- Install the .NET Core SDK -- Create a new project mkdir ConsoleApp cd ConsoleApp/
dotnet new dotnet restore dotnet run
-- Install Entity Framework
To add EF to your project, modify project.json so it matches the following sample.
{ "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": { "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0", "Microsoft.EntityFrameworkCore.Design": { "version": "1.0.0-preview2-final", "type": "build" } }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } }, "imports": "dnxcore50" } }, "tools": { "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" } }
Run dotnet restore again to install the new packages.
dotnet restore Verify that Entity Framework is installed by running dotnet ef --help.
dotnet ef --help
The issue
dotnet ef --help Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception message:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
### Further technical details
EF Core version: 1.0.0
Operating system: Windows 10
Visual Studio version: VS 2015 (though this is from command line)
Other details about my project setup: New Application
You can try to clear nuget cache and restore packages: https://github.com/aspnet/EntityFramework/issues/5458#issuecomment-221912806
That did the trick - thanks.
Glad to help. Especially because I have just spent the last two hours looking for a solution to the same problem.
I had the same issue, clearing the cache resolve it. Thanks!
I've been trying to resolve that error for 6 hours now, clearing the cache isn't resolving it for me. I can create a brand new project - ASP.NET Core Web Application (.NET Framework) And the initial Add-Migration throws the exception every time. I've also repaired/reinstalled the Microsoft .NET Core 1.0.0 - VS 2015 Tooling Preview 2 and reinstalled Visual Studio 2015 several times to fix the {B1C38f27...} bug which required Visual Studio 2013 to be installed.
Any other things I can try to get this to work?
Try uninstalling the old versions of .Net Core rc2 and the Tooling Preview 1. Then delete the cache.
Thanks for the input Ivan! I've just tried
- Uninstalling Microsoft .NET Core 1.0.0 SDK Preview 2
- Repairing Microsoft .NET Core 1.0.0 VS 2015 Tooling Preview 2
- del %USERPROFILE%.nuget\packages\Microsoft.EntityFrameworkCore.Tools
- del %USERPROFILE%.nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools
- Uninstalled Microsoft.EntityFrameworkCore.Tools v1.0.0-preview2-final
- Installed Microsoft.EntityFrameworkCore.Tools v1.0.0-preview2-final
- dotnet restore
log : Restoring packages for D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Restoring packages for tool 'BundlerMinifier.Core' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Restoring packages for tool 'Microsoft.AspNetCore.Razor.Tools' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Restoring packages for tool 'Microsoft.EntityFrameworkCore.Tools' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Restoring packages for tool 'Microsoft.Extensions.SecretManager.Tools' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Restoring packages for tool 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... log : Writing lock file to disk. Path: D:\GitHub\WebApplication4\src\WebApplication4\project.lock.json log : D:\GitHub\WebApplication4\src\WebApplication4\project.json log : Restore completed in 8209ms.
-
Edited project.json
"Microsoft.EntityFrameworkCore.Tools": { "version": "1.0.0-preview2-final", "imports": [ "portable-net45+win8" ] },
And I still get
- Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
@ZombiesWithCoffee don't use "imports" with preview 2. Clear your cache and try again. There is a bug in .NET Core CLI which does not re-install the tool if you have only changed "imports". https://github.com/dotnet/cli/issues/2978
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
That was the only time I used it, based on the #5458 comment.
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"BundlerMinifier.Core": "2.0.238",
....
-
del %USERPROFILE%.nuget\packages\Microsoft.EntityFrameworkCore.Tools
-
del %USERPROFILE%.nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools
-
dotnet restore
log : Restoring packages for tool 'Microsoft.EntityFrameworkCore.Tools' in D:\GitHub\WebApplication4\src\WebApplication4\project.json... -
Add-Migration Init
Same issue. Am I clearing my cache correctly?
@ZombiesWithCoffee are you deleting ".nuget\packages.tools" or ".nuget\packages.tools"? It should be the former. And can you share the contents of .nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools? (zip it up and add to comment thread)
del %USERPROFILE%.nuget\packages and del %USERPROFILE%.nuget\packages.tools the CLI tools and ProjectModels packages need to re-cached
Thank you NateMcMaster and VikSab!!! The bug in my process was the 'del' command! I had just copied it from the other thread, but just noticed that it wasn't deleting the subdirectories.
So, the correct way to delete your cache is (notice the /S)
del %USERPROFILE%.nuget\packages\Microsoft.EntityFrameworkCore.Tools /S
del %USERPROFILE%.nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools /S