Repository navigation
Description
ASP.NET Core supports integration with various single-page app (SPA) frameworks, including Angular, React, and React + Redux. Initially integration with these frameworks was accomplished with ASP.NET Core specific components that handled scenarios like server-side prerendering and integration with webpack. But as time went on, industry standards changed and the SPA frameworks each released their own standard command-line interfaces (e.g., Angular CLI, create-react-app).
When ASP.NET Core 2.1 was released in May 2018, we responded to the change in standards by providing a newer and simpler way to integrate with the SPA frameworks' own toolchains. This new integration mechanism exists in the package Microsoft.AspNetCore.SpaServices.Extensions and remains the basis of our Angular and React project templates since ASP.NET Core 2.1.
To clarify that the older ASP.NET Core specific components are not relevant or recommended, we are now officially obsoleting the pre-2.1 integration mechanism and marking the supporting NPM packages as deprecated.
The contents of the following NuGet packages have all been unnecessary since ASP.NET Core 2.1, and so are now being marked as obsolete:
- Microsoft.AspNetCore.SpaServices
- Microsoft.AspNetCore.NodeServices
For the same reason, the following NPM modules are being marked as deprecated:
- aspnet-angular
- aspnet-prerendering
- aspnet-webpack
- aspnet-webpack-react
- domain-task
These packages will later be removed in .NET 5. If you are using these packages, please update your apps to use the functionality in Microsoft.AspNetCore.SpaServices.Extensions instead along with the functionality provided by the SPA frameworks you are using. To enable features like server-side prerendering and hot module reload please refer to the documentation for the corresponding SPA frameworks. The functionality in Microsoft.AspNetCore.SpaServices.Extensions is not obsolete and will continue to be supported.
Activity
NotMyself commentedon Aug 6, 2019
Is UseWebpackDevMiddleware going away with this change? Or UseSpaStaticFiles?
flcdrg commentedon Aug 6, 2019
We've been using
Microsoft.AspNetCore.NodeServicesas a way of executing JavaScript in Node on the server from .NET Core - specifically by calling the InvokeAsync method(s).We'd previously been using the ClearScript library (in an earlier .NET Framework project), but that does not yet support .NET Core/.NET Standard.
If Microsoft.AspNetCore.NodeServices goes away, our only alternative would probably be to fork the source code.
CodeTherapist commentedon Aug 6, 2019
@NotMyself As far as I understand
UseWebpackDevMiddlewarewill go away andUseSpaStaticFileswill not.Seriously, I liked this webpack middleware with HMR, because it accelerates the inner loop and is more comfortable instead of having two processes (dev server + ASP.NET Core app). It also reflects more the production running app - that is served by ASP.NET Core using e.g. Kestrel.
I use it with vuejs (started with this obsoleted template).
I would appreciate, when useful libraries aren't become obsolete after years of supporting it. That weaknesses the trust using a library. At least, I expect a comprehensive migration guide for those who using the obsolete libraries.
Simon-Bull commentedon Aug 6, 2019
We use the
ISpaPrerenderer.RenderToString()functionality to server render a VueJS application, passing application context with thecustomDataParameter.Is there a recommended migration path to move to functionality in
Microsoft.AspNetCore.SpaServices.Extensions? This seems to useRenderToString()itself.bugproof commentedon Aug 6, 2019
Any reason why there's no official vue project template?
CodeTherapist commentedon Aug 6, 2019
@bugproof Maintaining templates isn't effortless. This has been discussed in issue: aspnet/JavaScriptServices/issues/412.
Sebazzz commentedon Aug 6, 2019
So how would HMR work with Webpack now? Webpack runs its own web server.
ericgreenmix commentedon Aug 6, 2019
My company also uses the
Microsoft.AspNetCore.NodeServicesto execute JS from .Net. Is there a recommended alternative, ifNodeServicesis going away?alexdresko commentedon Aug 6, 2019
I get the main gist of this issue, but losing
UseWebpackDevMiddlewareseems unfortunate. It works great for frameworks that don't have a CLI.atrauzzi commentedon Aug 6, 2019
I'm not sure I understand how
NodeServicesis related to this? What if people want to run JS code from C# for their own purposes?NotMyself commentedon Aug 6, 2019
@alexdresko I agree with you.
UseWebpackDevMiddlewareis a nice compromise to supporting multiple frameworks. I have been using it for around a year to do Vue.js development, example. It works quite nicely.296 remaining items
1kevgriff commentedon Feb 19, 2021
Might be worth keeping an eye on this issue: #27887
Luiz-Monad commentedon Feb 22, 2021
If you write F#, you can use https://fable.io/ to create isomorphic applications and share code between server and client.
This way you take backend code used for server-side rendering and compile it to JS and run inside node, instead of doing this hack of running node from aspnet core.
In some cases, you can run that and make it work barely enough to extract HTML and CSS from things like Material-UI.
rjgotten commentedon Feb 22, 2021
@Luiz-Monad
All the existing NodeServices does and is, is a thin layer of child process lifetime management and an HTTP loopback to facilitate communication.
The messy parts - and the only reason Microsoft could conceivably use as proper arguments to drop support - are in the JavaScript glue-code such as the
aspnet-webpackNPM package, the state of which I've expounded on before. There's nothing wrong with the approach on principle and it is honestly quite architecturally sound.I wouldn't exactly resort to calling a fairly standard and well-understood practice of inter-process communication over an HTTP loopback a 'hack' when compared to shoe-horning your entire application into an isomorphic rendering model that can fit yet another compiles-down-to-javascript cross-compiler. But maybe that's just me.
Luiz-Monad commentedon Feb 23, 2021
That's not the part that was a hack, its totally valid to use HTTP to do IPC between two different processes, The hack-part was the way it was starting the node server from inside that library.
I would much prefer something I control directly from the infrastructure side, like in docker or something, than starting gratuitous process in my production environment.
brunolau commentedon Feb 23, 2021
For anyone needing mostly the UseWebpackDevMiddleware extension method - I've attempted to port the Microsoft.AspNetCore.SpaServices library into .NET 5 by using the https://github.com/JeringTech/Javascript.NodeJS library.
Migration path:
That should do the trick...I've also attempted to port the Prerendering part, however as I've never used it and don't have time to learn just to test something I'll probably never use in production I haven't tested it
Source available on https://github.com/brunolau/BrunoLau.SpaServices
rjgotten commentedon Feb 24, 2021
Ah. If that's your beef, then iirc you can reconfigure the services collection with replacement classes that don't create a new node process and interface with it over local loopback, but which connect to an already running node process elsewhere.
Those parts should be replaceable as iirc one of the in-the-box replacements was to not use HTTP loopback but use named pipes.
vslzl commentedon Feb 24, 2021
Hello there, can anyone suggest a proper way to use ssr with recent versions of both asp.net and angular? for development I tried sth but for deployment it's not working at all. My old application was net core 3.1 with angular 11 works wit ssr but now I'm desperate...
brunolau commentedon Feb 24, 2021
@vslzl if you were using the Microsoft.AspNetCore.SpaServices library, you might try my port which is mentioned 2 comments above
alekkowalczyk commentedon Feb 24, 2021
@vslzl seems that the proper way is to split such app into ASP.NET back-end and node.js front-end for SSR, just wondering if there is an easy way to deploy such bundle into a single Azure AppService? 🤔
vslzl commentedon Feb 25, 2021
I'll try, thank you.
Exactly, I don't want to split my application in two parts. Single Pain Application is enough. No need to double them.
mopinsk commentedon Feb 26, 2021
You can create directories within your Azure AppService and make them virtual applications.
I've created a directory 'webapi' which serves requests to the '/webapi' endpoint (ASP.Net Core Web API, .Net 5) and a 'client' directory for my Angular SSR client (Angular 11), which serves everything but 'webapi'.
For node.js in an Azure AppService you need to enable the iisnode module in your web.config (which you can find in the 'deploy a node.js app to azure AppService' tutorial.
alekkowalczyk commentedon Feb 26, 2021
Interesting, how is it set-up in the dev environment? Is it within one
csproj? How does the deployment look like, possible through a single "Publish" from Visual Studio?mopinsk commentedon Feb 26, 2021
I don't have access to my development environment right now but I can give more information about my setup next week.
For publishing: I use Azure DevOps where I created a CI/CD pipeline that publishes whatever I have changed (either Angular Client or ASP.Net Core Web API, or both) to the AppService.
mopinsk commentedon Mar 7, 2021
I have finally had some time to create a repository and set up a little demo consisting of:
You can find my repo here: https://github.com/mopinsk/aspnetcore-angular-ssr
If you have any questions, feel free to open an issue in the repo. Hope I could help.