【发布时间】:2019-01-23 20:38:59
【问题描述】:
我正在将我的 asp.net core 2.2 Angular 7 Web 应用程序发布到 IIS,但出现以下错误:
- 确保已安装“npm”并且可以在 PATH 目录之一中找到。
- InvalidOperationException:无法启动“npm”。
- AggregateException:出现一个或多个错误。 (发生了一个或多个错误。(无法启动“npm”。要解决此问题:。[1] 确保已安装“npm”并且可以在 PATH 目录之一中找到)。
这适用于运行 IIS 8 的 Windows 2012 R2 服务器上的 Asp.Net 核心 Web 应用程序。 我的 IIS 8 本地机器也有同样的错误。
我的 launchsettings.json 个人资料:
"Test.IIS": {
"commandName": "IIS",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"ancmHostingModel": "InProcess",
"applicationUrl": "ttps://localhost:5002"
}
下面是我的 startup.cs 文件:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
//To check which process is runing the application
//app.Run(async (contenxt) => {
// await contenxt.Response.WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName);
//});
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
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");
}
});
}
代码编译成功,但在运行时抛出错误。
【问题讨论】: