我正在尝试在这里找到的“带有 Asp.Net Core 3.1 Web API 模板的 VueJS” ,它在开发过程中运行得非常顺利。但是,我想看看它是如何处理发布的,但我无法让它发挥作用。
运行发布到文件夹时,它不会将 clientapp/dist 文件夹移动到输出目录,这没关系,所以我想我会手动执行。因此,我尝试使用以下路径将 dist 文件夹的内容移动到输出目录:
- “/发布/clientapp/dist”
- “/发布/分发”
- “/发布/客户端应用程序”
但以上似乎都不起作用,运行 .dll 文件时出现以下错误:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLTD93CRG52F", Request id "0HLTD93CRG52F: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.
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.<Attach>b__1(HttpContext context, Func`1 next)
at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.<Use>b__1(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.TryServeStaticFile(HttpContext context, String contentType, PathString subPath)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_2.<Use>b__2()
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.<Attach>b__0(HttpContext context, Func`1 next)
at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.<Use>b__1(HttpContext context)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
这是我在 Startup.cs 中的“UseSpa”:
app.UseSpa(spa =>
{
if (env.IsDevelopment())
spa.Options.SourcePath = "ClientApp";
else
spa.Options.SourcePath = "clientapp/dist";
if (env.IsDevelopment())
{
spa.UseVueCli(npmScript: "serve");
}
});
使用上面的代码,我假设我的 dist 文件夹应该位于 /publish/clientapp/dist 中,我已经尝试过,但即便如此,我也会收到上面提到的错误。
我希望有人能指出我正确的方向 - 在此先感谢:)