实体框架工具使用生产作为默认环境值

时间:2017-11-12 14:49:06

标签: asp.net-core entity-framework-core asp.net-core-2.0

在ASP.NET Core 2.0应用程序上,我正在运行命令:

dotnet ef database update

从迁移创建数据库...

但是,该命令从生产设置中选择连接字符串,而不是从开发设置中选择。

该应用程序的Program.cs如下:

  public class Program {

    public static void Main(String[] args) {    
      BuildWebHost(args).Run();       
    }

    public static IWebHost BuildWebHost(String[] args) {

      IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);

      IWebHost host = builder
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((context, configuration) => {

          IHostingEnvironment environment = context.HostingEnvironment;

          configuration
            .AddJsonFile("settings.json", false, true)
            .AddJsonFile($"settings.{environment.EnvironmentName}.json", false, true)
            .AddEnvironmentVariables();

          if (environment.IsDevelopment()) {     
            configuration.AddUserSecrets<Startup>();            
          }          

        })
        .ConfigureLogging((context, logging) => { })
        .UseStartup<Startup>()
        .Build();

      return host;

    }

  }

如何使Entity Framework工具使用开发环境?

0 个答案:

没有答案