How to change the Namespace of a C#project

Asked

Viewed 3,531 times

11

The project was created with the name Windows and I want to change. The problem is that if I just right-click the project and rename it, the project gets full of error. I tried to change Assembly name and Default namespace but it also causes a lot of error.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

What is the correct way to rename? if possible.

  • If you changed the name of the project, did not change the namespace. Which one do you want to actually change? Give more details of how the project is going, post a screenshot of it, some piece of code that is relevant, ponde is giving error.

  • I put a print of the places I want to change. If I change these places, from the error in the project in general, it does not compile.

  • Give examples of errors presented.

1 answer

12


I do it this way:

  • Ctrl + Shift + H;
  • Search expression (Find what): "using Windows;", or "namespace Windows"
  • Replace with (Replace with): "using Novonomedenamespace;" (attention to keeping the semicolon signs at the end), or else "namespace Novonomedenamespace";
  • Find in (Look in): Entire solution (Entire Solution).

Some tools do it for you, like Resharper, but it’s not free, so that would be the no-cost way.


About Assembly Name and Default Workspace:

The reasoning is the same. First change the names in the properties, then run the procedure described above, because the renaming of the namespaces is not automatic.

  • 1

    Gypsy, thank you very much. I have Resharper and I will try to change for him.

  • @Gypsy Morrison Mendez, what is the difference between these name, default Workspace and namespace? All must always contain the same name?

  • @Danover Assembly Name is the name the DLL will have. Default Namespace is the Namespace root of the project. I don’t know what Default Workspace is. No, not everyone should always have the same name. It depends on what you need to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.