So I was watching a channel 9 video on Angular CLI with .Net Core here: https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Angular-and-NET-Core
At position 8:15 he demos auto-syncing where updating a .ts
file in the Angular CLI folder compiled on save, then later caused the view to update. I tried this an it does not update at all (unless I refresh the whole page).
I also noticed that the template does not work out of the box (big surprise). I managed to update it to the newer Angular version (and ran into an error where the template had incorrectly created "start": "ng serve --extract-css",
to package.json
where --extract-css
is invalid and had to remove it). I also assumed that Visual Studio (2017) would compile Angular on its own, but it did not, so I added this to the project file:
<Target Name="NgDebug" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
<!--Run Angular build in debug mode (NOTE: does not support symbolic links nor junction points)-->
<Message Importance="high" Text="Building the Angular code in debug (dev) mode ..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="ng build" />
</Target>
<Target Name="NgRelease" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Release' ">
<!--Run Angular build in prod mode (NOTE: does not support symbolic links nor junction points)-->
<Message Importance="high" Text="Building the Angular code in release (prod) mode ..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="ng build --prod" />
</Target>
Two questions here:
- Is this sync feature expected to work today? Is there a configuration required?
- Am I expected to setup the
ng build
step myself, or is there a different method I should be using for the ASP.Net Core (with Angular CLI) template?
Here is the app.UseSpa
code:
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");
}
});