ASP.NET Core 6 : separate SPA and API projects

Viewed 1197

When I create a new ASP.NET Core 6 project with Angular in VS 2022 it wires up everything so when I press F5 it will start both angular and .net projects. Great, but can these projects be separated?

Why do I need this? Angular project is almost done so there are no modifications on it. Starting an Angular project takes time and I don't want to wait every time I hit F5 to start the Angular project.

In a previous version of ASP.NET, I could start the angular project manually and use UseProxyToSpaDevelopmentServer to redirect requests to that server. In ASP.NET Core 6, UseProxyToSpaDevelopmentServer does not work.

Is there a solution for this?

1 Answers

You can create a asp.net core project without a SPA application. Having the SPA embedded in the server is optional. For some cases it is beneficial. For example you easy utilize server sided rendering.

The separated template for just API it's called ASP.NET Core Web API. (From CLI dotnet new webapi) In this case you will have to make sure the SPA is calling the right port of your locally running server instance.

To speed up development you could separate the API and or use file watcher to rebuild and run as you save files. You can do that with CLI dotnet watch run in the project folder.

Related