C# ASP.NET核心部署到Azure不迁移数据库

C# ASP.NET核心部署到Azure不迁移数据库,c#,azure,visual-studio-2015,asp.net-core,C#,Azure,Visual Studio 2015,Asp.net Core,到现在为止,我已经工作了一整天,想让我的应用程序部署到Azure上,但无法让它工作,而它以前工作得很好 此时,我甚至删除了整个Webapp、数据库和数据库服务器。 我已经更新了一些软件包,但在这一点上没有错误 工具 我已经把所有安装的工具都放在这里了。也许有一个我不知道的冲突 ASP.NET核心>=1.0.1和EF核心>=1.0.1 Visual Studio 2015企业版及其更新(包括ReSharper) 实体框架6.1.3 Visual Studio 2015工具 Microsoft.N

到现在为止,我已经工作了一整天,想让我的应用程序部署到Azure上,但无法让它工作,而它以前工作得很好

此时,我甚至删除了整个Webapp、数据库和数据库服务器。
我已经更新了一些软件包,但在这一点上没有错误

工具 我已经把所有安装的工具都放在这里了。也许有一个我不知道的冲突

  • ASP.NET核心>=1.0.1和EF核心>=1.0.1
  • Visual Studio 2015企业版及其更新(包括ReSharper)
  • 实体框架6.1.3 Visual Studio 2015工具
  • Microsoft.NET Core 1.0.1-SDK 1.0.0预览版2-003131(x64)
  • Microsoft.NET Core 1.0.1-VS 2015工具预览版2
  • Microsoft.NET Core 1.0.3-SDK 1.0.0预览版2-003156(x64)
  • Microsoft.NET Core 1.1.0-SDK 1.1.0预览版2.1-003177(x64)
  • Microsoft.NET Framework 4.5多目标包
  • Microsoft.NET Framework 4.5.1多目标包
  • Microsoft.NET Framework 4.5.1多目标包(ENS)
  • Microsoft.NET Framework 4.5.1 SDK
  • Microsoft.NET Framework 4.5.2多目标包
  • Microsoft.NET Framework 4.5.2多目标包(ENS)
  • Microsoft.NET Framework 4.6 SDK
  • Microsoft.NET Framework 4.6目标软件包
  • Microsoft.NET Framework 4.6目标软件包(简体中文版)
  • Microsoft.NET Framework 4.6.1 SDK
  • Microsoft.NET Framework 4.6.1目标软件包
  • Microsoft.NET Framework 4.6.1目标软件包(简体中文版)
  • Microsoft.NET版本管理器(x64)1.0.0-rc1
  • Microsoft Azure应用程序服务工具v2.9.6-Visual Studio 2015
  • Microsoft Azure创作工具-v2.9.5.1
  • Microsoft Azure命令行工具
  • Microsoft Azure.NET库-v2.9
  • 适用于Visual Studio 2015的Microsoft Azure工具-v2.9
  • Microsoft Web部署3.6
  • Microsoft Web平台安装程序5.0
project.json web.config 这些是默认设置

<?xml version="1.0" encoding="utf-8"?>
<configuration>    
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>
[
  {
    "outputFileName": "wwwroot/css/site.min.css",
    "inputFiles": [
      "wwwroot/css/site.css"
    ]
  },
  {
    "outputFileName": "wwwroot/js/site.min.js",
    "inputFiles": [
      "wwwroot/js/site.js"
    ],
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    "sourceMap": false
  }
]
bundleconfig.json 这些是默认设置

<?xml version="1.0" encoding="utf-8"?>
<configuration>    
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>
[
  {
    "outputFileName": "wwwroot/css/site.min.css",
    "inputFiles": [
      "wwwroot/css/site.css"
    ]
  },
  {
    "outputFileName": "wwwroot/js/site.min.js",
    "inputFiles": [
      "wwwroot/js/site.js"
    ],
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    "sourceMap": false
  }
]
Startup.cs 这没有任何效果,但也没有出现任何错误

Azure门户 我开始关注Azure门户网站上发生的事情,在这里我注意到了一些事情

已部署Web应用程序 web应用已部署,但数据库尚未迁移。只要我不点击需要查看数据库的页面,一切都正常

数据库查询 虽然数据库中没有任何内容(默认表除外),但似乎执行了一些查询。

我真的希望有人看到这一点,并能告诉我这里发生了什么


提前谢谢

您正在使用EF Core迁移吗?这是我正在寻找的,但无法使其工作。你能告诉我该怎么做吗?根据你的代码,我们可以发现你调用
DbInitializer.Initialize()
方法在Configure方法的末尾初始化数据库,请检查传递给Initialize方法的上下文对象的实际ConnectionString,并确保它是否连接到您的Azure SQL数据库。在尝试了更多之后,我只是选择创建一个新项目并复制到目前为止创建的类。它又起作用了。
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Verbonding.Data;
using Verbonding.Models;
using Verbonding.Services;
using Microsoft.AspNetCore.Identity;

namespace Verbonding
{
    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);

            if (env.IsDevelopment())
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();

                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }

            builder.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)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddMvc();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
        }

        // 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,
            ApplicationDbContext context)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            var userManager = app.ApplicationServices.GetService < UserManager<ApplicationUser>>();
            DbInitializer.Initialize(context, userManager, Configuration["Password"]);
        }
    }
}
<appSettings>
    <add key="MigrateDatabaseToLatestVersion" value="true" />
</appSettings>