14

I'm trying to create a new ASP.NET Core project with Angular using Visual Studio 2022. I selected the Angular template during project creation. However, after the project is generated, I get the following error when opening it:

Could not find file 'D:\Experiments\Experiments\AngularApp2\angularapp2.client\src\app\app.component.ts' Things I noticed:

Before this error, Visual Studio prompted me about sharing anonymous project creation data with Google (Angular telemetry), and I clicked No.

I already installed Node.js and Angular CLI globally using:

npm install -g @angular/cli

I tried to Deleting the project and creating it again (still same error) Reinstalling Angular CLI But sadly didn't worked nor I was able to find any proper solution about it. Any guidance or a workaround to fix this would be appreciated.

2
  • Could you please check, if the file exists? Angular changed the naming conventions during the last major release (no 'component'). I guess the project template does not work together with the latest cli and you may need to fix the generated project files by your own or there is already an update for the project template. Commented Jun 22 at 12:09
  • @ThomasRenger of course file doesn't exist can you please provide more details to fix it thanks. Commented Jun 23 at 4:50

7 Answers 7

23

I believe you currently have Angular 20 installed.

Previously, the app file was called "app.component.ts". But since Angular 20, the naming convention has changed to remove ".component", ".directive", and similar names from files.

Visual Studio does not know this, so it is looking for "app.component.ts" when Angular 20 has generated "app.ts".

This is a Visual Studio bug that is currently being fixed. They had similar issues when Angular moved away from using modules.

In the meantime, I suggest using Angular 19 instead:

npm install -g @angular/cli@v19

Edit: If you need to use Angular 20 before this is fixed:

The Angular 20 announcement post explains that new projects can enable old naming convention using the following schematic configuration in angular.json:

{
  "projects": {
    "app": {
      ...
      "schematics": {
        "@schematics/angular:component": { "type": "component" },
        "@schematics/angular:directive": { "type": "directive" },
        "@schematics/angular:service": { "type": "service" },
        "@schematics/angular:guard": { "typeSeparator": "." },
        "@schematics/angular:interceptor": { "typeSeparator": "." },
        "@schematics/angular:module": { "typeSeparator": "." },
        "@schematics/angular:pipe": { "typeSeparator": "." },
        "@schematics/angular:resolver": { "typeSeparator": "." }
      },
  ...
}

You will still get the error when the template is generated, but adding this configuration may prevent further issues.

Also, please keep in mind that depending on how Angular is supported by Visual Studio in the future, this naming convention may not be recognized for Angular 20 projects.

Sign up to request clarification or add additional context in comments.

5 Comments

My Good!, NOT (downgrading never is a good solution). If you want to use the same "name convention", just change the angular.json like show in the blog -the section "Style guide updates"-. Apologies, I downvote the answer, because I think it is wrong full)
Hi Eliseo, thank you for the additional information. I still believe that since this issue is specific to new projects, using Angular 19 instead of 20 for a new project may be a valid solution for some developers. Additionally, the solution you've provided will not prevent the original Visual Studio error, but it may prevent further issues with Visual Studio, so I've included it in my answer in case some people find it useful. Thanks.
Thank you. npm install -g @angular/cli@v19 worked perfectly for me.
Thx. Downgrading version to 19 solved it.
While downgrading seems awfull, this isn't realy an issue. You can go back to 20 once the sollution is created.
2

Had the same issue. Worked around it by using the Angular app template (without ASP core) and creating a second project with the ASP core API template.

Apparently only the Angular app template is updated.

Comments

1

I found a workaround that worked for me.

I uninstalled the current version of an angular cli and installed the version 19 lts.

npm remove -g @angular/cli

npm intall -g @angular/cli@v19-lts

After that, it created the project for me.

1 Comment

see my comment about downgrading.
1

I solved it by not using the combined template. Just created Angular 20 project with CLI in VS Code and Web API in Visual Studio, then ran both (ng serve for Angular and run API from VS). Worked fine.

Comments

0

From error above message, it seems there is mismatch or conflict between Angular CLI version that you have installed and what VS template expects or generates. My advice, you can test to downgrade your Angular CLI to v16. If still not working, you can try to create your Angular project using Angular CLI (in separate folder).

Comments

0

Possible Reason I don't have the actual template, but I imagine in the folder ClientApp/src you have a file called main.ts.

This is the file that is executed when your program.cs indicates something like this:

if (builder.Environment.IsDevelopment())
{
    app.UseSpa(spa =>
    {
        spa.Options.SourcePath = "ClientApp";
        spa.UseAngularCliServer(npmScript: "start");
    });
}

Specifically, you indicate to execute the main.ts file in the package.json file. (In the ClientApp folder)

If you use a standalone component as the "entry point", the main.ts file will have something like this:

    //see that you bootstrap a Component
    bootstrapApplication(AppComponent, config);

If your angular application uses modules, you should "bootstrap" the app module with:

    //see that you bootstrap a Module
    platformBrowserDynamic().bootstrapModule(AppModule)
      .catch(err => console.error(err));

Possible Solutions

  1. Change the main.ts to use modules (not recommended)
  2. Create an angular application using ng-client in another place and copy the folder into your ClientApp folder

Comments

0

The problem is with .NET. They look for the names:

app.component.ts
app.component.html
app.component.spec.ts
app.component.css
app.module.ts

If those names are not there, the project fails to complete the project creation.

The solution I found is to create the project like normal and have it fail. Then add those files:

app.component.ts
app.component.html
app.component.spec.ts
app.component.css
app.module.ts

Then go back to the project creation screen and click create again. Choose the options to overwrite the current solution and it should be created correctly after this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.