c# - .NET Core NuGet EF Core 版本不匹配

标签 c# visual-studio entity-framework .net-core

我正在学习本教程:Tutorial

我搜索了大约 4 个小时,没有找到解决此错误的方法:

Startup project 'DatabaseConnection' is an ASP.NET Core or .NET Core project for Visual Studio 2015. This version of the Entity Framework Core Package Manager Console Tools doesn't support these types of projects.

我使用以下命令生成它:

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') OK https ://api.nuget.org/v3/registration1-gz/microsoft.entityframeworkcore.tools/index.json 143ms Error finding repository for 'https ://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/': An error occurred while retrieving package metadata for 'Microsoft.EntityFrameworkCore.Tools.1.1.0-msbuild3-final' from source 'Microsoft and .NET'. A task was canceled. Retrieving package 'Microsoft.EntityFrameworkCore.Tools 1.1.0-msbuild3-final' from 'nuget.org'. Installing NuGet package Microsoft.EntityFrameworkCore.Tools.1.1.0-msbuild3-final. Successfully installed 'Microsoft.EntityFrameworkCore.Tools 1.1.0-msbuild3-final' to DatabaseConnection Executing nuget actions took 122.12 ms Time Elapsed: 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 2015 .Netcore 数据项目为代码优先项目创建数据迁移时遇到了类似的错误:

“启动项目‘Company.Application.Data’是 Visual Studio 2015 的 ASP.NET Core 或 .NET Core 项目。此版本的 Entity Framework Core 包管理器控制台工具不支持这些类型的项目。”

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

  1. 导航到项目目录(在我的例子中是 f:_dev\Company.Application.Data)
  2. 类型:dotnet 恢复
  3. 添加新的迁移示例类型:dotnet ef migrations add MyExampleMigrationName
  4. 您的迁移应该出现在 visual studio 中
  5. 根据需要编辑您的新迁移

关于c# - .NET Core NuGet EF Core 版本不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42207992/

相关文章:

entity-framework - 为什么在 Entity Framework 6中仍未实现ON DELETE SET NULL?有障碍吗?

c# - 异步 EntityFramework 操作

c++ - 错误 LNK2019 : unresolved external symbol

Git 卡在增量对象上

c# - 跟踪 Entity Framework 进度

sql-server - Entity Framework /SQL Server 许多外键

c# - WPF 如何设置 CollectionViewSource 的最大结果量

c# - 更新 XML 文件 (C#/Linq)

c# - PLINQ、任务、异步、生产者/消费者队列?用什么?

visual-studio-2010 - 程序集绑定(bind)重定向和代码分析