.NET Core NuGet EF Core版本不匹配

5
我正在遵循这篇教程:教程 我搜索了大约4个小时,没有找到解决以下错误的方法:
“启动项目'DatabaseConnection'是Visual Studio 2015的ASP.NET Core或.NET Core项目。此版本的Entity Framework Core软件包管理器控制台工具不支持这些类型的项目。”
我使用以下命令生成它:
Scaffold-DbContext "Server=127.0.0.1;Database=vicotv;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

以下是我尝试更新EF SQL服务器的过程。

PM> Install-Package Microsoft.EntityFrameworkCore.Tools -Version 1.1.0-msbuild3-final

GET https://api.nuget.org/v3/registration1-gz/microsoft.entityframeworkcore.tools/index.json

GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/Packages(Id='Microsoft.EntityFrameworkCore.Tools',Version='1.1.0-msbuild3-final')

成功 https://api.nuget.org/v3/registration1-gz/microsoft.entityframeworkcore.tools/index.json,共耗时143毫秒

'https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/' 找不到仓库: 从源 'Microsoft and .NET' 检索 'Microsoft.EntityFrameworkCore.Tools.1.1.0-msbuild3-final' 的包元数据出现错误。

一个任务被取消了。

正从 'nuget.org' 检索包 'Microsoft.EntityFrameworkCore.Tools 1.1.0-msbuild3-final'。

正在安装 NuGet 包 Microsoft.EntityFrameworkCore.Tools.1.1.0-msbuild3-final。

已将 'Microsoft.EntityFrameworkCore.Tools 1.1.0-msbuild3-final' 成功安装到 DatabaseConnection。

执行 nuget 操作共耗时 122.12 毫秒。

流逝的时间: 00:00:00.9439736

但是由于这个错误,该软件包没有更新。

以下是我的 project.json 文件内容:

{
"buildOptions":{
    "emitEntryPoint":true,
    "preserveCompilationContext":true
},
"dependencies":{
    "Microsoft.EntityFrameworkCore.SqlServer":"1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design":"1.1.0",
    "Microsoft.ApplicationInsights.AspNetCore":"2.0.0",
    "Microsoft.AspNetCore.Mvc":"1.1.1",
    "Microsoft.AspNetCore.Routing":"1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration":"1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel":"1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables":"1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions":"1.1.0",
    "Microsoft.Extensions.Configuration.Json":"1.1.0",
    "Microsoft.Extensions.Logging":"1.1.0",
    "Microsoft.Extensions.Logging.Console":"1.1.0",
    "Microsoft.Extensions.Logging.Debug":"1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions":"1.1.0",
    "Microsoft.NETCore.App":"1.1.0",
    "Microsoft.EntityFrameworkCore.Design":"1.1.0",
    "Microsoft.EntityFrameworkCore":"1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools":"1.1.0-preview4-final",
    "Microsoft.EntityFrameworkCore.Tools":"1.1.0-msbuild3-final"
},
"frameworks":{
    "netcoreapp1.0":{
        "imports":[
            "dotnet5.6",
            "portable-net45+win8"
        ]
    }
},
"publishOptions":{
    "include":[
        "wwwroot",
        "**/*.cshtml",
        "appsettings.json",
        "web.config"
    ]
},
"runtimeOptions":{
    "configProperties":{
        "System.GC.Server":true
    }
},
"scripts":{
    "postpublish":[
        "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
    ]
},
"tools":{

},
"runtimes":{
    "win10-x86":{

    },
    "win10-x64":{

    }
}}

我的dotnet信息:

PM> dotnet --info

.NET命令行工具 (1.0.0-preview2-1-003155)

产品信息:

版本: 1.0.0-preview2-1-003155

提交SHA-1哈希值: d7b0190bd4

运行环境:

操作系统名称: Windows

操作系统版本: 10.0.14393

操作系统平台: Windows

RID: win10-x64

我应该做什么?


你使用的 Visual Studio 版本和项目中使用的 .net framework 版本是什么? - Baro
@Baro 我正在使用VisualStudio 2015专业版,我在我的项目中使用的.NET框架是:.NET Framework 4.5.2,我的项目是ASP.Net Core Web应用程序。 - joshii_h
6
尝试在你的project.json中使用"Microsoft.EntityFrameworkCore.Tools":"1.1.0-preview4-final"代替msbuild3,因为你正在使用project.json(而且显然不是VS2017)。请注意,翻译时已经尽力使内容更加简单易懂,但原意未被改变。 - Pawel
@christopherclark 你需要安装VS 2017,然后它就可以正常工作了。 - joshii_h
PM> dotnet -restore - whiteshooz
显示剩余6条评论
1个回答

1

我在使用Visual Studio 2015 .Netcore数据项目为基础创建数据迁移时,遇到了类似的错误:

"启动项目'Company.Application.Data'是一个ASP.NET Core或.NET Core项目,不支持这些类型的项目的Entity Framework Core包管理器控制台工具。"

通过以下步骤使用PowerShell解决:

  1. 导航到项目目录(在我的情况下是f:_dev\Company.Application.Data)
  2. 键入:dotnet restore
  3. 添加新的迁移示例类型:dotnet ef migrations add MyExampleMigrationName
  4. 您的迁移应该出现在Visual Studio中
  5. 根据需要编辑您的新迁移

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接