How to add an implementation of IDesignTimeDbContextFactory to add migration to .Net core 2.0 application?

后端 未结 3 1007
眼角桃花
眼角桃花 2021-01-17 21:16

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 abl

相关标签:
3条回答
  • 2021-01-17 21:41

    Had the same issue. It happened after i updated Microsoft.AspNetCore.All from 2.0.0-preview2-final to 2.0.0. Guess the reason why it fails is that i have .NET Core Preview 2 runtime installed.

    EFCore got updated too. So please, make sure you have same nuget and runtime versions

    UPDATE: Now .NET Core runtime and SDK 2.0 released https://www.microsoft.com/net/download/core. After install you can safely update your packages to 2.0.0

    0 讨论(0)
  • 2021-01-17 21:45

    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();
    }
    

    This class changed with dotnet core 2.0.0

    0 讨论(0)
  • 2021-01-17 22:05

    I had the same issue

    My solution contained a console application and an api application which contained the dbcontext code.

    I had set the start up project to the console application. When I changed the start up project to the api application the error dissapeared.

    0 讨论(0)
提交回复
热议问题