How can I rename my c# namespace to include a dot
Asked Answered
M

2

9

I want to rename my namespace, MyProjectTest.Core to MyProject.Test.Core, but the Visual Studio 2017 refactoring tool doesn't let me insert . into the name.

I do not want to do that manually, is there another option?

Mot answered 9/10, 2018 at 12:38 Comment(2)
what you mean it doesn't let you insert .? You can rename namespace and add as many .s as you want.Amenable
As is only apparent in the answer (but ought to be in the question), this appears to specifically be talking about performing a rename via the Refactoring tool.Catchpole
M
18

It is correct, you can not use your keyboard key . to enter a dot, however, you can use CTRL+C to copy the dot character (from this answer, if you want) and then insert the dot into the name with CTRL+V.

Note: Visual Studio 2017 will complain about invalid characters, but it will rename it anyway if you click apply:

Visual Studio 2017 complaining about the invalid character 1 Visual Studio 2017 complaining about the invalid character 2

Mot answered 9/10, 2018 at 12:38 Comment(3)
How could I do if I want to change from "My.Project" to "My.Project.Core", for example. When I select "My.Project" then crtl + r + crtl + r to rename the ide just select "My"Tonnie
Be careful with such renames since it could lead to unexpected changes. E. g. renaming of MyProject part in MyProject.Test.Core will rename all instances of all namespaces started with MyProject, not only MyProject.Test.Core. And adding a dot to the new name will make undo quite hard.Hath
Doesn't work in VS2022, but still works in VS2019, great answer.Kennith
S
-1

Goto project properties and change the default namespace.

Sedulous answered 28/9, 2023 at 11:34 Comment(1)
Your answer looks either incomplete because you mean doing this in combination with the "Sync namespaces" action on the project (moreover I doubt it exists in VS 2017) or wrong because changing the default namespace of the project alone will only affect files generated after the change and not existing files. I suggest that you either edit to add more details or simply delete your answerYabber

© 2022 - 2024 — McMap. All rights reserved.