1 year ago

#266338

test-img

SigmaScout_12

How to add SPA Services for AngularJS project with .NET Core?

I'm rebuilding a project of mine from .NET Framework to .NET Core and was curious to see if I'm able to "plug" in my Angular JS front-end project into the new .NET Core project using SpaServices. I've found some tutorials and this is what I have (my Angular folder is in the same project as my Startup.cs and API):

In ConfigureServices() in Startup.cs:

services.AddSpaStaticFiles(config => {
      config.RootPath = "/MyAngularProject";
});

In Configure() in Startup.cs:

app.UseSpa(spa => {
     spa.Options.SourcePath = "/MyAngularProject";
     if (env.IsDevelopment())
         {
              spa.UseAngularCliServer(npmScript: "start");
         }
});

The Angular folder is not named 'ClientApp'. When I run my backend and then the Angular project in VS Code, I get this error:

AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.

There is also an Inner Exception:

[2] See the InnerException for further details of the cause.
 ---> System.ComponentModel.Win32Exception (267): The directory name is invalid.

I've looked and made sure my PATH variable is set to the node.js folder and the error is still being thrown. I don't think I'm pointing at the wrong directory either for my Angular project. I do have the package.json file that holds the start script in a folder within MyAngularProject. I've also tried navigating into that folder but it produces the same errors. Can anyone help point me in the right direction? Is this even possible given the project is AngularJS? Thank you for any help!

UPDATE:

Here is the folder structure:

Solution 'MyProject'
   MyProject.API
      Controllers (folder)
      MyAngularProject (folder)
          app (folder)
               [npm script is located in here]
      Startup.cs
      Program.cs
      appsettings.json

c#

angularjs

asp.net-core

asp-net-core-spa-services

0 Answers

Your Answer

Accepted video resources