【发布时间】:2019-01-30 01:41:15
【问题描述】:
尝试将我的项目生成为exe文件,但出现错误:
之前:“dotnet build -r win10-x86”没问题
运行生成的exe后,一切正常:
indows DPAPI to encrypt keys at rest.
Hosting environment: Production
Content root path: C:....\currencyColution\correncyProject\bin\Debug\netcoreapp2.1\win10-x86
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
加载页面损坏后,更准确地说是找不到 index.html:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLG91TC2H0UO", Request id "0HLG91TC2H0UO:00000001": An
unhandled exception was thrown by the application.
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.
Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.
Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.IO;
using Microsoft.AspNetCore.Http;
namespace AspNetCore2Ang6Template
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSpaStaticFiles(c =>
{
c.RootPath = "wwwroot";
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(name: "default", template: "{controller}/{action=index}/{id}");
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "wwwroot";
});
}
}
}
我不使用angular和其他一些,只是尝试打开wwwroot/index.html
文件:
货币项目
wwwroot Program.cs Startup.cs
在 VS 中测试,一切正常,但不是通过 exe builder
像 dev : dotnet run 一样启动,然后它可以在 localhost:58893/ 上运行,但是在 localhost:5000 上构建 prod dotnet 有什么问题
启动设置:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:58842/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AspNetCore2Ang6Template": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:58893/"
}
}
}
【问题讨论】:
-
我也尝试过这样做,它对我有用。你如何启动exe?任何参数添加或smth?您使用的是哪个版本的 .Net?
-
@Zysce, Microsoft.AspNetCore.All 2.1.2, Microsoft.AspNetCore.SpaServices 2.1.1, exe 作为管理员和用户启动,没有任何参数
-
@Zysce,可能是 Port, 5000, 5001 设置 exe builder,但通过 IDE 端口是 58843 并且可以正常工作
-
@Zysce,我在 VMware Fusion 上使用 Windows 10,dotnet 2.1.4
-
@Zysce,像 dev : dotnet run 一样启动,然后它可以在 localhost:58893/ 上运行,但是在 localhost:5000 上构建的 prod dotnet 有什么问题
标签: c# .net asp.net-mvc binary