将ASP.NET核心部署到Azure不会迁移数据库
我现在一整天都在将我的应用程序部署到Azure,但无法使其工作,而以前它像魅力一样工作。
此时我甚至删除了整个Webapp,数据库和数据库服务器。
我更新了一些软件包,但在这一点上没有错误。
工具
我已经安装了所有的工具。 也许可能会有我不知道的冲突。
project.json
{
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"dependencies": {
"Microsoft.AspNetCore.AzureAppServicesIntegration": "1.0.0",
"BundlerMinifier.Core": "2.2.281",
"CsvHelper": "2.16.3",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.1",
"Microsoft.AspNetCore.Diagnostics": "1.0.1",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.1",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.1",
"Microsoft.AspNetCore.Mvc": "1.0.2",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview4-final",
"Microsoft.AspNetCore.Routing": "1.0.2",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.2",
"Microsoft.AspNetCore.StaticFiles": "1.0.1",
"Microsoft.EntityFrameworkCore": "1.0.2",
"Microsoft.EntityFrameworkCore.Design": "1.0.2",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.2",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.2",
"Microsoft.EntityFrameworkCore.Tools": {
"type": "build",
"version": "1.0.0-preview4-final"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.1",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.0.1",
"Microsoft.Extensions.Logging.Debug": "1.0.1",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.1",
"Microsoft.NETCore.App": "1.0.3",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"type": "build",
"version": "1.0.0-preview4-final"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"tools": {
"BundlerMinifier.Core": "2.2.281",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"userSecretsId": "aspnet-Verbonding-67a1a892-cfc3-493a-bb8c-5ddc0637d3db",
"runtimes": {
"win10-x64": {}
}
}
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=".logsstdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": ""
},
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)mssqllocaldb;Database=######;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
bundleconfig.json
这些是默认设置
[
{
"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
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"]);
}
}
}
发布
连接
连接设置在连接到Azure后由Visual Studio / Azure设置
设置
我认为这是可能出错的地方。
有一个文字说Discovering data contexts
。 我期望在这里看到我的上下文类,但几秒钟后它停下来,并没有显示任何东西
发现数据上下文后的设置
连接字符串也由Visual Studio / Azure自动添加。 我检查了连接字符串中的值,他们似乎没有问题。
有些事情我已经尝试过了:
更新软件包
将软件包更新到版本1.1.0。 这并没有达到预期的效果。 如果有任何事情似乎会让事情变得更糟。 最后,我最终将版本1.0.1安装到1.0.3
在Azure上进行全新安装
我删除了WebApp,数据库和数据库服务器并重新安装它们。
清理并重建项目
我已经清理并重建了几次这个项目,甚至每次我做了一些改变。 没有解决任何问题。
将代码添加到web.config
<appSettings>
<add key="MigrateDatabaseToLatestVersion" value="true" />
</appSettings>
这没有任何影响,但它也没有给出任何错误。
Azure门户
我开始研究Azure门户发生的事情,在这里我注意到了一些事情。
部署Web应用程序
Web应用程序已部署,但数据库尚未迁移。 只要我没有打开需要查看数据库的页面,一切正常。
数据库查询
虽然数据库中没有任何内容(缺省表除外),但似乎有一些查询已执行。
我真的希望有人看到这件事,并能告诉我这里发生了什么事。
提前致谢。
链接地址: http://www.djcxy.com/p/21297.html上一篇: ASP.NET core deploy to Azure not migrating database
下一篇: Use full .NET Framework with existing ASP.NET Core project