迁移应用程序时无法加载类型 'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions'
Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions' while Migrating application
我正在使用 VS Code 开发 .Net Core RTM web api。当我 运行 命令 dotnet ef migrations add "myfirstMigraion"
进行迁移时,出现如下图所示的错误。 :-
我的 project.json 文件看起来像:-
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.EntityFrameworkCore.Design": {
"type": "build",
"version": "1.0.0-preview2-final"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions":"1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "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": "1.0.0-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final",
// "Microsoft.EntityFrameworkCore.Tools":"1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.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,
"debugType": "portable"
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [
"dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
]
},
"tooling": {
"defaultNamespace": "firstCoreApi"
}
}
看起来像我的 Startup.cs :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using firstCoreApi.Model;
namespace firstCoreApi
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var connection = @"Server=myPcName\SQLEXPRESS; Database=StudentsDB;user id=MysqlUserId;password=Mysqlpassword;Trusted_Connection=True;MultipleActiveResultSets=true";
//Server=SQLSERVERNAME;Database=StudentsDB;user id=sa;password=sa1;Trusted_Connection=True;MultipleActiveResultSets=true;
// Add framework services.
services.AddMvc();
// services.AddDbContext<TodoListDbContext>(options => options.UseInMemoryDatabase());
services.AddDbContext<BloggingContext>(options => options.UseSqlServer(connection));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
}
}
我正在使用操作系统 Windows 10 和 sql 服务器 2014。我需要你的帮助,伙计们如何修复它。
我也出现了同样的异常,我只是 "Microsoft.AspNetCore.Routing": "1.0.0-rc2-final" 更改为 "Microsoft.AspNetCore.Routing": "1.0.0"。它的工作
我认为如果您使用 VSCODE,您可以尝试在 project.json
中进行更改
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0"
我遇到了同样的问题。从命令行安装包。求助网站:https://www.nuget.org/packages/Kendo.Mvc/2016.2.630-Preview
在包管理器中使用的命令:Install-Package Kendo.Mvc -Pre
NuGet returns搜索到的包是最新的稳定包,里面有bug,哈哈!这就是为什么您需要从包管理器中的命令行安装的原因。
Telerik 知道这个问题:https://github.com/telerik/kendo-ui-core/issues/1856
我正在使用 VS Code 开发 .Net Core RTM web api。当我 运行 命令 dotnet ef migrations add "myfirstMigraion"
进行迁移时,出现如下图所示的错误。 :-
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.EntityFrameworkCore.Design": {
"type": "build",
"version": "1.0.0-preview2-final"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions":"1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "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": "1.0.0-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final",
// "Microsoft.EntityFrameworkCore.Tools":"1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.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,
"debugType": "portable"
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [
"dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
]
},
"tooling": {
"defaultNamespace": "firstCoreApi"
}
}
看起来像我的 Startup.cs :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using firstCoreApi.Model;
namespace firstCoreApi
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var connection = @"Server=myPcName\SQLEXPRESS; Database=StudentsDB;user id=MysqlUserId;password=Mysqlpassword;Trusted_Connection=True;MultipleActiveResultSets=true";
//Server=SQLSERVERNAME;Database=StudentsDB;user id=sa;password=sa1;Trusted_Connection=True;MultipleActiveResultSets=true;
// Add framework services.
services.AddMvc();
// services.AddDbContext<TodoListDbContext>(options => options.UseInMemoryDatabase());
services.AddDbContext<BloggingContext>(options => options.UseSqlServer(connection));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
}
}
我正在使用操作系统 Windows 10 和 sql 服务器 2014。我需要你的帮助,伙计们如何修复它。
我也出现了同样的异常,我只是 "Microsoft.AspNetCore.Routing": "1.0.0-rc2-final" 更改为 "Microsoft.AspNetCore.Routing": "1.0.0"。它的工作
我认为如果您使用 VSCODE,您可以尝试在 project.json
中进行更改"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0"
我遇到了同样的问题。从命令行安装包。求助网站:https://www.nuget.org/packages/Kendo.Mvc/2016.2.630-Preview
在包管理器中使用的命令:Install-Package Kendo.Mvc -Pre
NuGet returns搜索到的包是最新的稳定包,里面有bug,哈哈!这就是为什么您需要从包管理器中的命令行安装的原因。
Telerik 知道这个问题:https://github.com/telerik/kendo-ui-core/issues/1856