【发布时间】:2017-08-10 08:35:21
【问题描述】:
我正在尝试使用 Angular CLI 生成的 Angular 应用设置 ASP.NET Core 项目。
我已经设置了两件事,以便我可以:
- 在 VS Code 中通过 F5 启动和调试服务器(ASP.NET Core)
- 构建 Angular 应用并通过终端使用
ng build --watch观察更改。
现在,我想将这两件事结合起来,以便在我调试 ASP.NET Core 项目时自动构建和监视 Angular 文件。但我不知道该怎么做。我在.csproj-file 中试过这个:
<Target Name="PostcompileScript" AfterTargets="Build">
<Exec Command="ng build --watch" />
</Target>
但这会卡在watch 部分,无法继续调试项目。
关于如何让这个工作的任何想法?
我的目标:
- 托管在 ASP.NET Core 项目中的 Angular 应用程序(而不是
ng serve) - 使用
ng build而不是运行自定义 webpack 脚本 - 某种实时重新加载,以便在调试时在浏览器中自动更新对我的
ts文件的更改。
这可能吗?
编辑
我认为这无关紧要,但这是我的 angular cli 配置文件:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "my-app"
},
"apps": [
{
"root": "src",
"outDir": "wwwroot",
"assets": [
"assets",
"content/imgs",
"favicon.ico"
],
"index": "index.html",
"main": "app.ts",
"polyfills": "polyfills.ts",
"tsconfig": "tsconfig.app.json",
"prefix": "app",
"styles": [
"content/styles/styles.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"testing": "environments/environment.testing.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"defaults": {
"styleExt": "scss",
"component": {}
}
}
还有.csproj 文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
</ItemGroup>
<Target Name="PostcompileScript" AfterTargets="Build">
<Exec Command="ng build --watch" />
</Target>
</Project>
【问题讨论】:
-
用配置文件更新帖子
-
@Aravind 角度 cli 配置?为什么这很重要?
-
当然是相关的。
-
@Aravind 我已经添加了它 :) 但我的问题不是我的 Angular 应用程序不工作,所以我认为配置很好。我的问题是如何将 Angular 应用程序的构建和监视与调试 ASP.Net Core 项目结合起来
-
@Joel 你能分享 csproj 文件吗?
标签: angularjs angular asp.net-core .net-core angular-cli