實體框架核心腳手架訪問方法失敗

asp.net-core asp.net-core-1.1 entity-framework-core

運行以下命令後:

dotnet ef dbcontext scaffold
"Server=SERVERNAME;Database=MYDATABASE;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -o Models -f

我收到此錯誤:

發生了一個或多個錯誤。 (通過方法'Microsoft.EntityFrameworkCore.Scaffolding.Configuration.Internal.ModelConfiguration.get_EntityConfigurations()'嘗試訪問方法'Microsoft.EntityFra meworkCore.Metadata.Internal.EntityTypeNameComparer..ctor()'失敗。)

project.json:

{
  "userSecretsId": "aspnet-APPLICATION-0799fe3e-6eaf-4c5f-b40e-7c6bfd5dfa9a",
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
    "Microsoft.Extensions.Logging.Abstractions": "1.1.0",
    "Newtonsoft.Json": "9.0.1",
    "Microsoft.AspNetCore.Mvc.Versioning": "1.0.2"
  },
  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "appsettings.json",
      "web.config"
    ]
  },
  "scripts": {
    "prepublish": [
      "npm install",
      "bower install",
      "gulp clean",
      "gulp min"
    ],
    "postpublish": [
      "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
    ]
  },
  "tooling": {
    "defaultNamespace": "APPLICATION"
  }
}

Dotnet版本:1.0.0-preview2-1-003177

跟踪所有版本並使它們協同工作變得不可能。

一般承認的答案

所以解決方案是:

"dependancies":{
   "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
}

"tools": {
   "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
   "Microsoft.EntityFrameworkCore.Tools.DotNet": " 1.1.0-preview4-final"
},

熱門答案

在安裝.NET Core 1.1 SDK之前,我遇到了各種錯誤。

https://www.microsoft.com/net/download/core#/current

是的 - 1.1版本的文件名是dotnet-dev-win-x64.1.0.0-preview2-1-003177.exe

在我之前和之後

C:\Users\SimonWeaver>dotnet --version
1.0.0-preview2-003131

C:\Users\SimonWeaver>dotnet --version
1.0.0-preview2-1-003177

現在工具可以很好地用於腳手架。

再回過頭來看,我已經看到你已經安裝了這個,但我會把它留在這里以防萬一其他人沒有。



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow