【问题标题】:Adding Angular 5 to ASP.Net MVC 5 application breaks build将 Angular 5 添加到 ASP.Net MVC 5 应用程序会中断构建
【发布时间】:2018-05-04 14:04:06
【问题描述】:

设置:

  1. ASP.Net MVC 5 应用程序 (v4.5.2)。
  2. Angular (v5.2.0) 在 MVC 应用程序中使用 angular-cli(v1.7.4)。
  3. Angular 应用程序在 www.mydomain.com/app 上运行。
  4. Angular 应用程序加载到 AppController 的索引视图中。
  5. 使用 BundleConfig.cs 引用 dist 文件夹中必要的 JS 和 CSS 输出文件。
  6. 构建过程已修改为使用 .csproj 文件构建 Angular 应用程序。
  7. ng build 使用 -extract-css(-ec),因此 Index.cshtml 文件不必在开发和生产之间进行更改。
  8. 到目前为止一切正常。

.csproj:

<Target Name="NgDebug" BeforeTargets="Build" Condition="'$(Configuration)' == 'Debug'">
    <Exec WorkingDirectory="$(ProjectDir)admin-client" Command="ng build -ec" />
  </Target>
  <Target Name="NgRelease" BeforeTargets="Build" Condition="'$(Configuration)' == 'Release'">
    <Exec WorkingDirectory="$(ProjectDir)admin-client" Command="ng build --prod" />
  </Target>

问题:

  1. 将 --watch (-w) 添加到 Command="ng build -ec" 时,构建将无限期挂起并且不会引发任何错误。
  2. 构建输出挂起:1&gt;------ Build started: Project: CorpNet.Admin.Web, Configuration: Debug Any CPU ------

我的解决方案:

应用程序启动后,我通过命令行运行 ng build -ec -w 并且一切正常。

问题:

如何将--watch (-w) 添加到ng build -ec 作为构建过程的一部分,而不是从命令行手动运行?

【问题讨论】:

    标签: asp.net-mvc angular asp.net-mvc-5 angular-cli csproj


    【解决方案1】:

    你不应该。

    构建需要命令才能完成。即使您从构建中生成了一个监视进程,您也无法控制该应用程序的生命周期。

    因此,在 csproj 构建期间进行一次构建是可以的,但在构建完成后,不应留下任何额外的过程。根据您用于构建的工具,一个 csproj 文件甚至可以构建多次(设计时构建与实际构建)。

    但是,您可以从应用程序内部运行 Angular 命令,以便 Angular Cli 可以在应用程序运行时重建您的客户端部分。

    对于 ASP.NET Core,可以使用 SPA 服务轻松设置,该服务负责将 Angular CLI 与 ASP.NET Core 管道(2.0 的可安装模板,集成在即将推出的 2.1 工具中)。见Use the Angular project template with ASP.NET Core

    【讨论】:

    • 您能否详细说明从我的应用程序运行角度命令。此外,ASP.NET Core 不是此项目的选项。
    猜你喜欢
    • 2018-11-15
    • 2021-06-28
    • 1970-01-01
    • 2018-05-29
    • 2016-09-30
    • 2016-10-17
    • 2014-04-14
    • 1970-01-01
    • 2016-09-20
    相关资源
    最近更新 更多