问题
I'm trying to use EntityFrameworkCore@3.1. In order to do this at this point I already have: - Installed Visual Studio 2019 Preview - Installed the .NET Core 3.1 Runtime - Installed the .NET Core 3.1 SDK
Now I still can't run the command dotnet ef migrations add xxx
. It's saying that I have to update the dotnet tools. So I run the following command in an administrator powershell:
PS C:\WINDOWS\system32> dotnet tool update --global dotnet-ef
Tool 'dotnet-ef' was reinstalled with the latest stable version (version '3.0.0')
Okay, not including the preview versions. So I try to specify the version explicitly:
PS C:\WINDOWS\system32> dotnet tool update --global dotnet-ef --version="3.1.0-preview1.19506.2"
error NU1202: Package dotnet-ef 3.1.0-preview1.19506.2 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / any. Package dotnet-ef 3.1.0-preview1.19506.2 supports: netcoreapp3.1 (.NETCoreApp,Version=v3.1)
Tool 'dotnet-ef' failed to update due to the following:
The tool package could not be restored.
Tool 'dotnet-ef' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
Now it's saying that a .NET Core 3.1 tool is not compatible with the .NET Core 3.1 runtime.
However, if I do a simple version check:
PS C:\WINDOWS\system32> dotnet --version
3.1.100-preview1-014459
PS C:\WINDOWS\system32> dotnet ef --version
Entity Framework Core .NET Command-line Tools
3.0.0
I can see that the EntityFrameworkCore.Tools is still at version 3.0.0 instead of 3.1.0 (which tools version is installed in my project).
Am I still missing something or is this a bug?
回答1:
Known bug - https://github.com/dotnet/cli/issues/12963. Does not provide a solution though.
回答2:
Thanks to @lars-haupt-hansen for pointing me to the bug, I followed the trail to the PR which shows it was merged into "aspnet:release/3.1". The latest 3.1 is still a preview (preview3). You can find and download the latest SDK here.
To use it in Visual Studio projects, you have to
- install the SDK from the above link;
- go to Tools > Options > Environment > Preview Features and enable "Use previews of the .NET Core SDK";
- restart VS
- Go to each project properties, and then you can choose the Target Framework
.NET Core 3.1
Then to install EF Core via the command line, run dotnet tool install --global dotnet-ef --version 3.1.0-preview3.19554.8
from your project directory.
回答3:
dotnet tool install -g dotnet-ef --version 3.0.0-preview4.19216.3
dotnet tool install --global dotnet-ef --version 3.0.0-preview8.19405.11
来源:https://stackoverflow.com/questions/58549046/update-net-core-tools