简体   繁体   中英

ASP.NET MVC running Entity Framework command on the command line

I want to run dnx commands from command line in Visual studio, but it does not work.

If I type the command:

 dnx ef

I get the error:

System.InvalidOperationException: No service for type 'Microsoft.Dnx.Runtime.IApplicationEnvironment' has been registered.
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Data.Entity.Commands.Program..ctor(IServiceProvider dnxServices)

My project.json contains this:

 "dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Commands": "7.0.0-beta8",
    "Microsoft.Framework.SecretManager": "1.0.0-beta8"
 },

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
},

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }
},

DNX version:

 Microsoft .NET Execution environment
 Version:      1.0.0-rc1-16231
 Type:         Clr
 Architecture: x86
 OS Name:      Windows
 OS Version:   10.0
 Runtime Id:   win10-x86

DNVM version:

 1.0.0-rc1-15540

DNVM list:

 Active Version           Runtime Architecture OperatingSystem Alias
 ------ -------           ------- ------------ --------------- -----
     1.0.0-rc1-update1 clr     x64          win
*    1.0.0-rc1-update1 clr     x86          win             default
     1.0.0-rc1-update1 coreclr x64          win
     1.0.0-rc1-update1 coreclr x86          win

I figured it out. If you get errors like this, it probably if because of wrong dependencies. They need to match your environment and other dependencies. I installed the lates of them all and it worked. This is my final dependencies:

 "dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "Microsoft.Framework.SecretManager": "1.0.0-beta8"
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM