【问题标题】:Run .NET Core application with specific angular configuration运行具有特定角度配置的 .NET Core 应用程序
【发布时间】:2021-09-24 10:09:18
【问题描述】:

我在 Angular 中有带有前端的 .NET Core 应用程序。我想用特定的配置和主机运行我的应用程序。当我在脚本中添加到 package.json 时

"start": "ng serve --configuration=myconf--host myhost",
"build": "ng build --configuration=myconf"

我可以使用dotnet run 运行我的应用程序,一切正常,但我不想在我的package.json 中更改startbuild。我可以做某事吗

"start": "ng serve"
"start:myconf": "ng serve --configuration=myconf --host myhost",
"build": "ng build" 
"build:myconf": "ng build --configuration=myconf" 

在我的 package.json 中并在命令行中指定配置和主机?我试过dotnet run start:myconfdotnet run --configuration=myconf --host myhost 但它不起作用。 我可以用其他方式吗?

【问题讨论】:

  • 这仅用于开发吗? .net 核心应用如何提供对 Angular 应用的访问?
  • 是的,我只想在本地使用它进行开发。
  • 您是否在使用带有 UseSpa() 的 dotnet new angular 项目模板?该代码块是如何配置的?

标签: angular .net-core


【解决方案1】:

如果您使用的是dotnet new angular 模板,那么您可以更改 spa 脚本。

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:myconf");
        // spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
    }
});

【讨论】:

    【解决方案2】:

    就我的目的而言,在 Angular 应用程序中运行 ng build --configuration=myconf --host myhost 就足够了,然后使用 dotnet run 运行我的应用程序。 package.json 中无需编辑任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      相关资源
      最近更新 更多