無法在mac上使用dotnet ef core搭建腳手架

.net .net-core c# entity-framework entity-framework-core

我正在嘗試使用.net內核從我MAC上的現有數據庫中反向設計模型類。數據庫在帶有Windows的VM中運行,我可以從osx連接到它。

在我的project.json中,我有以下內容:

"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.AngularServices": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",

    "Microsoft.EntityFrameworkCore.Design": {
      "type": "build",
      "version": "1.0.0-preview2-final"
    },
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "compile": {
      "exclude": ["node_modules"]
    }
  }

但是當我跑步的時候

dotnet ef dbcontext scaffold "myDbConnectString" Microsoft.EntityFrameworkCore.SqlServer

我收到以下錯誤,我無法通過這個

 An error occurred while calling method 'ConfigureDesignTimeServices' on startup class

“Microsoft.EntityFrameworkCore.Scaffolding.SqlServerDesignTimeServices”。考慮使用IDbContextFactory在設計時覆蓋DbContext的初始化。錯誤:無法從程序集“Microsoft.Extensions.DependencyInjection.Abstractions,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60”加載類型“Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions”。 System.AggregateException:發生一個或多個錯誤。 (嘗試激活'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'時,無法解析類型'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory'的服務。)---> System.InvalidOperationException:無法解析類型'Microsoft的服務。嘗試激活'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'時EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory'。在Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider提供程序,ISet 1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet 1 callSiteChain) 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet 1 callSiteChain)中的.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService服務,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet (類型serviceType,ServiceProvider serviceProvider )在Microsoft的Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)中的System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd [TKey,TValue,TArg](ConcurrentDictionary 2 dictionary, TKey key, Func 3 valueFactory,TArg arg)。 Extensions.DependencyInjection.Service Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(Microsoft提供者,String connectionString,String outputDir,String dbContextClassName,Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T](IServiceProvider provider)上的ProviderServiceExtensions.GetRequiredService(IServiceProvider提供程序,類型serviceType)。在IE.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider,String connectionString,String outputDir,String dbContextClassName,IEnumerable 1 schemaFilters, IEnumerable 1 tableFilters,IEnumerable 1 schemas, IEnumerable 1 tables,Boolean useDataAnnotations,Boolean overwriteFiles,CancellationToken cancellationToken)在Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.d__1.MoveNext()---內部異常堆棧跟踪的結束---在System.Threading.Tasks.Task.Thro的布爾useDataAnnotations,Boolean overwriteFiles,CancellationToken cancellationToken) 1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) ---> (Inner Exception #0) System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) ---> (Inner Exception #0) System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet 1 callSiteChain,ParameterInfo []參數,Boolean throwIfCallSiteNotFound)Microsoft的Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider提供程序,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor的Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(類型serviceType,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet 1 callSiteChain) 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary 3 valueFactory, TArg arg) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary 2字典,TKey鍵,Func 3 valueFactory, TArg arg) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable 1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable 1 schemaFilters,IEnumerable`1 tableFilters 1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable 3 valueFactory, TArg arg) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable 1 schemas,IEnumerable 1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable ,Boolean.DataTnnotations,Boolean overwriteFiles,CancellationToken cancellationToken)at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.d__1.MoveNext()<---發生了一個或多個錯誤。 (嘗試激活'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'時,無法解析類型'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory'的服務。)

我試圖來回更改我的依賴項的版本,但沒有結果。任何人有任何指針?

一般承認的答案

剛剛開始工作。我更新到.net核心1.1.0並修改了我的project.json以使用更新的版本。希望這可以幫助別人

project.json:

"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.1.0",
    "type": "platform"
  },
  "Microsoft.AspNetCore.AngularServices": "1.0.0-*",
  "Microsoft.AspNetCore.Diagnostics": "1.1.0",
  "Microsoft.AspNetCore.Mvc": "1.1.0",
  "Microsoft.AspNetCore.Razor.Tools": {
    "version": "1.1.0-preview4-final",
    "type": "build"
  },
  "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
  "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
  "Microsoft.AspNetCore.StaticFiles": "1.1.0",
  "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
  "Microsoft.Extensions.Configuration.Json": "1.1.0",
  "Microsoft.Extensions.Configuration.CommandLine": "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.EntityFrameworkCore.Design": {
    "type": "build",
    "version": "1.1.0"
  },
  "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
  "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0"
},

"tools": {
  "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
  "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
  "Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final",
  "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
}

熱門答案

您是否嘗試過使用RTM版本的Entity Framework?

{
  "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
  "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1"
}


Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因