问题描述
我正在尝试从.NET Core 2.0 MVC应用程序的程序包管理器控制台中运行Add-Migration InitialCreate命令.在查看了所有可能的来源之后,仍然无法解决错误说明如下的问题:
I am trying to run Add-Migration InitialCreate command from package manager console from a .NET Core 2.0 MVC application. After looking at all possible sources still not able to resolve the issue with error description as :
PM> Add-Migration InitialCreate
Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
我的Program.cs如下:
My Program.cs looks like:
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
public static IWebHost BuildWebHost(string[] args) =>
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
}
还为
public class ToDoContextFactory : IDesignTimeDbContextFactory<MvcMovieContext>
{
public MvcMovieContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<MvcMovieContext>();
builder.UseSqlServer("Server=(local);Database=MvcMovieContext;Trusted_Connection=True;MultipleActiveResultSets=true");
return new MvcMovieContext(builder.Options);
}
}
有人可以通过逐步描述性程序来帮助我,以便将模型和Entity Framework工具添加到.NET Core2.0 App中.
Can someone help me with a descriptive step by step procedure to add model and Entity Framework tools to a .NET Core2.0 App.
推荐答案
您需要更改课程Program
You need change your class Program
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
此类已更改使用dotnet core 2.0.0
This class changed with dotnet core 2.0.0
这篇关于如何添加IDesignTimeDbContextFactory的实现以将迁移添加到.Net Core 2.0应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!