由 dotnet new Angular
从 Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0
生成的 *.csproj
文件 [docs]似乎将这些命令呈现为相同:dotnet run
和 npm start
。
每当我打算从需要启动的 Visual Studio Code 运行 SPA 和 ASP.NET Core 后端时(按 F5)。运行 dotnet run
will not run both 。
这种情况是故意设计的吗?我不应该在 VS Code 中使用 dotnet run
吗?
最佳答案
对于 dotnet run
和 npm start
,它们完全不同。 dotnet run
用于启动 .Net Core
项目,npm start
用于启动 Angular
项目。
按 F5
会同时启动 Core
和 Angular
项目的原因是,从 VS Code
启动时code>,Environemnt
为 Development
,然后 Startup.Configure
将运行以下代码:
spa.UseAngularCliServer(npmScript: "start");
UseAngularCliServer
将调用 StartAngularCliServerAsync
为您启动 Angular
项目,该项目对应于运行 npm start
。
如果您想从 dotnet run
启动 Angular
和 Core
项目,有两种选择
- 在 Windows 操作系统中从 CommandLin 运行
SET ASPNETCORE_Environment=Development
并在 Linux 或 MacOS 中运行export ASPNETCORE_Environment=Development
删除启动中的
if (env.IsDevelopment())
。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 spa.Options.SourcePath = "ClientApp"; // if (env.IsDevelopment()) // { // spa.UseAngularCliServer(npmScript: "start"); // } spa.UseAngularCliServer(npmScript: "start"); });
关于asp.net-core - 使用 Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0 时, `dotnet run` 与 `npm start` 没有什么不同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51529003/