无法在mac

时间:2016-11-16 23:54:07

标签: c# .net entity-framework entity-framework-core .net-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&#39 ;.   考虑使用IDbContextFactory来覆盖初始化   DbContext在设计时。错误:无法加载类型   ' Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions'   来自assembly' Microsoft.Extensions.DependencyInjection.Abstractions,   Version = 1.0.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60'。           System.AggregateException:发生一个或多个错误。 (无法解析类型的服务   ' Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory'   在尝试激活时   ' Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator&#39 ;.)   ---> System.InvalidOperationException:无法解析类型的服务   ' Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory'   在尝试激活时   ' Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator&#39 ;.              在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)              在Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService)   服务,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet 1 callSiteChain)              在Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type   serviceType,ServiceProvider serviceProvider)              at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd [TKey,TValue,TArg](ConcurrentDictionary 2 dictionary, TKey key, Func 3 valueFactory,TArg arg)              在Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type   服务类型)              在Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider)   提供者,类型serviceType)              在Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T](IServiceProvider   提供商)              在Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String   provider,String connectionString,String outputDir,String   dbContextClassName,IEnumerable 1 schemas, IEnumerable 1个表,   Boolean useDataAnnotations,Boolean overwriteFiles,CancellationToken   的CancellationToken)              在Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String   provider,String connectionString,String outputDir,String   dbContextClassName,IEnumerable 1 schemaFilters, IEnumerable 1   tableFilters,Boolean useDataAnnotations,Boolean overwriteFiles,   取消语音取消语言)              在Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.d__1.MoveNext()              ---内部异常堆栈跟踪结束---              在System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)              在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 []参数,布尔值   throwIfCallSiteNotFound)              在Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider)   提供者,ISet 1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet 1 callSiteChain)              在Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type   serviceType,ISet 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个模式,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,Boolean useDataAnnotations,Boolean overwriteFiles,   取消语音取消语言)              在Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.d__1.MoveNext()< ---           发生了一个或多个错误。 (无法解析类型的服务   ' Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory'   在尝试激活时   ' Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'。)

我试图来回更改我的依赖项的版本,但没有结果。有人有指点吗?

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用RTM版本的Entity Framework?

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

答案 1 :(得分:0)

刚刚开始工作。 我更新到.net核心1.1.0并修改了我的project.json以使用更新的版本。希望这可以帮助别人 project.json: "依赖":{   " Microsoft.NETCore.App":{     "版本":" 1.1.0",     "输入":"平台"   },   " Microsoft.AspNetCore.AngularServices":" 1.0.0 - *",   " Microsoft.AspNetCore.Diagnostics":" 1.1.0",   " Microsoft.AspNetCore.Mvc":" 1.1.0",   " Microsoft.AspNetCore.Razor.Tools":{     "版本":" 1.1.0-preview4-final",     "输入":" 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":{     "输入":" build",     "版本":" 1.1.0"   },   " Microsoft.EntityFrameworkCore.SqlServer.Design":" 1.1.0",   " Microsoft.EntityFrameworkCore.SqlServer":" 1.1.0" }, "工具":{   " 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" }