devbf
devbf

Reputation: 571

How to properly change the name of a Blazor component (razor file)

I have a problem I´m a little irritated with: Let´s say I have a Blazor component MyCustomComponent.razor which is located at ProjectName.Client.Shared. Now I can use it in my code like this:

<MyCustomComponent></MyCustomComponent>.

But as soon as I rename that component via right click on MyCustomComponent.razor to for example MyFirstCustomComponent.razor, still only the old component name appears in IntelliSense and the new one doesn´t get recognized. This error message appears:

Found markup element with unexpected name 'MyFirstCustomComponent.razor'. If this is intended to be a component, add a @using directive for its namespace.

Even if I do a full rebuild, nothing happens.

My current solution is to delete the old component and to create a new component with the new name, but that´s not really a good way to do this in my opinion.

Is there a place where I also have to change the old name to the new name in some other file? I couldn´t find any appearance of the old component name in my code after renaming, but it was still somehow there to select from IntelliSense...

Upvotes: 1

Views: 2681

Answers (2)

Wesley King
Wesley King

Reputation: 21

My visual studio does this as well, however usually after closing all the affected files from the editing window intellisense catches up. Sometimes it takes a few minutes, I just carry on working till it clears. Maybe try rebuilding the cache, which will then make it act 'normal' going forward?

Upvotes: 1

Gary Chan
Gary Chan

Reputation: 558

It sounds like the Intellisense database is corrupted. The easiest thing to do is to rebuild it.

This is what I do:

  1. Close solution and exit Visual Studio
  2. Delete the *.suo file in the .vs folder
  3. Restart Visual Studio and reopen solution

The Intellisense database will be rebuilt.

Upvotes: 1

Related Questions