要求git
.net core 2.1
引用包github
Microsoft.AspNetCore.SpaServices
先在angular目錄下執行npm
npm i npm run build
關鍵代碼c#
services.AddSpaStaticFiles(c => { //這裏設置路由 c.RootPath = "ClientApp/dist"; });
app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 //這裏是angular項目的根目錄 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } });
示例代碼app
經過 ASP.NET Core 使用 Angular 項目模板
Implement ASP.NET Core SPA template features in an Angular 6 appide