我有一个基于ASP.NET Core 1.0的项目。我可以在没有任何问题的情况下在本地构建和运行,但是如果我尝试使用Visual Studio 2015中的发布机制将项目发布到Azure(即使我尝试在本地发布到文件系统中的文件夹或使用FTP),它也会意外地失败而没有给我任何具体的信息。如果我运行预览,我总是得到这个日志:
The "Publish" task failed unexpectedly.
System.Exception:
Publishing Project.Web for .NETFramework,Version=v4.5.2/win7-x64
at Microsoft.DotNet.Tasks.Publish.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
如果我尝试发布忽略此错误,或者如果我不尝试获取预览,我会得到这个:
1>------ Publish started: Project: Kunato.Web, Configuration: Debug Any CPU ------
rmdir /S /Q "C:\Users\thimo\AppData\Local\Temp\PublishTemp\Kunato.Web54\"
Environment variables:
DOTNET_CONFIGURE_AZURE=1
Path=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "C:\Code\Git\Web_KuNaTo\src\Kunato.Web" --framework net452 --output "C:\Users\thimo\AppData\Local\Temp\PublishTemp\Kunato.Web54" --configuration Debug --no-build
Publishing Kunato.Web for .NETFramework,Version=v4.5.2/win7-x64
1>Publish failed due to build errors. Check the error list for more details.
========== Build: 0 succeeded, 0 failed, 7 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
如果我按要求执行并查看错误列表,则没有错误,一切看起来都不错。是否有其他日志文件或任何内容可以检查问题所在?
project.json
{
"userSecretsId": "aspnet-Kunato.Web-753ff034-0ada-4809-84a8-a4f157c4ea43",
"dependencies": {
"Kunato.Common": "1.0.0-*",
"Kunato.Core": "1.0.0-*",
"Kunato.DataAccess": "1.0.0-*",
"Kunato.Edi": "1.0.0-*",
"Kunato.Entities": "1.0.0-*",
"Kunato.Localization": "1.0.0-*",
"ediFabric.Framework": "6.7.0",
"LumenWorksCsvReader": "3.9.0",
"Sendgrid": "6.3.4",
"StackExchange.Redis": "1.1.0-alpha2",
"StackExchange.Redis.StrongName": "1.1.0-alpha2",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0",
"Microsoft.AspNetCore.Authentication.Google": "1.0.0",
"Microsoft.AspNetCore.Authentication.MicrosoftAccount": "1.0.0",
"Microsoft.AspNetCore.Authentication.Twitter": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.AspNetCore.Cors": "1.0.0",
"Microsoft.AspNetCore.Session": "1.0.0",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.Caching.Redis": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"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"
]
}
},
"frameworks": {
"net452": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
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 Kunato.Web.Services;
using Kunato.DataAccess;
using Kunato.Entities.Core;
using Kunato.Web.Helpers;
using System.Globalization;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Options;
using Kunato.DataAccess.Data;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Kunato.Web
{
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 Application Insights data collection services to the services container.
services.AddApplicationInsightsTelemetry(Configuration);
// Add framework services.
services.AddDbContext<KunatoDatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Kunato.Web")));
services.AddIdentity<KunatoUser, KunatoRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 4;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-.";
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<KunatoDatabaseContext>()
.AddDefaultTokenProviders();
// Add session
services.AddSession(options =>
{
options.CookieName = ".kunato.Session";
options.IdleTimeout = TimeSpan.FromMinutes(30);
});
// Add localization
services.AddLocalization();
// Register Version service
services.AddSingleton<IDeploymentEnvironment, DeploymentEnvironment>();
// Add localization to the request pipeline
var dtf = new DateTimeFormatInfo
{
ShortDatePattern = "dd.MM.yyyy",
LongDatePattern = "dd.MM.yyyy HH:mm",
ShortTimePattern = "HH:mm",
LongTimePattern = "HH:mm"
};
var nf = new NumberFormatInfo
{
CurrencyDecimalSeparator = ",",
CurrencyGroupSeparator = ".",
NumberDecimalSeparator = ",",
NumberGroupSeparator = ".",
NumberDecimalDigits = 3
};
// Add MVC services to the services container.
services.AddMvc().AddJsonOptions(options =>
{
// handle loops correctly
options.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
// use standard name conversion of properties
options.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();
// include $id property in the output
options.SerializerSettings.PreserveReferencesHandling =
PreserveReferencesHandling.Objects;
})
.AddViewLocalization()
.AddDataAnnotationsLocalization();
// Register Filters
services.AddScoped<LanguageActionFilter>();
services.Configure<RequestLocalizationOptions>(
options =>
{
var supportedCultures = new List<CultureInfo>
{
//new CultureInfo("en-US") { DateTimeFormat = dtf },
//new CultureInfo("en") { DateTimeFormat = dtf },
new CultureInfo("de-DE") { DateTimeFormat = dtf, NumberFormat = nf },
new CultureInfo("de") { DateTimeFormat = dtf, NumberFormat = nf }
//new CultureInfo("en-US"),
//new CultureInfo("en"),
//new CultureInfo("de-DE"),
//new CultureInfo("de")
};
options.DefaultRequestCulture = new RequestCulture(culture: "de-DE", uiCulture: "de-DE");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
// Add application settings from config
services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
// Register KunatoBaseData
//services.AddTransient<KunatoBaseData>();
//services.AddTransient<KunatoSampleData>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Add Application Insights to the request pipeline to track HTTP request telemetry data.
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<KunatoDatabaseContext>().Database.Migrate();
// Seeding the basic data to the database
var kunatoBaseData = app.ApplicationServices.GetService<KunatoBaseData>();
await kunatoBaseData.InitializeDataAsync();
// Seeding sample data to the database
//var kunatoSampleData = app.ApplicationServices.GetService<KunatoSampleData>();
//await kunatoSampleData.InitializeDataAsync();
}
}
catch { }
app.UseStaticFiles();
app.UseIdentity();
// Add session
app.UseSession();
// Add localization
var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(locOptions.Value);
// 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?}");
});
}
}
}