ASP.NET core deploy to Azure not migrating database
I have been working all day by now to get my app deployed to Azure, but can't get it to work, while it previously worked like a charm.
At this point I even deleted the entire Webapp, database and database server.
I have updated some packages, but at this point there are no errors.
Tools
I have put all the tools here that are installed. Maybe there might be a conflict that I am not aware of.
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
These are the default settings
<?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
These are the default settings
[
{
"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"]);
}
}
}
Publish
Connection
The connection settings are set by Visual Studio / Azure after connecting to Azure
Settings
I thinks this is where it might go wrong.
There is a text saying Discovering data contexts
. I would expect here to see my context class, but after a couple of seconds it stops and does not show anything
Settings after discovering data contexts
The connection string is also added automatically by Visual Studio / Azure. I have checked the values in the connection string and they seem to be all right.
Some things I have already tried:
Update packages
Updating the packages to version 1.1.0. This did not have the desired effect. If anything it seemed to make things worse. In the end I ended up installing to version 1.0.1 to 1.0.3
Clean installation on Azure
I removed the WebApp, database and database server and reinstalled them.
Clean and rebuild the project
I have cleaned and rebuilt the project a couple of times, and even every time I made some changes. Did not solve anything.
Add code to web.config
<appSettings>
<add key="MigrateDatabaseToLatestVersion" value="true" />
</appSettings>
This did not have any effect, but it also did not give any errors.
Azure portal
I started looking at what happened at the Azure portal, here I noticed a couple of things.
Web app deployed
The web app is deployed, but the database has not migrated. As long as I do not hit a page that needs to look into the database, everything works fine.
Database queries
While there is nothing in the database (except for the default tables), there seem to be some queries executed.
I really hope someone is seeing this and can tell me what is going on here.
Thanks in advance.
链接地址: http://www.djcxy.com/p/21298.html