Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to NOT include Visual Studio Project folder names in generated namespaces

How do I prevent the name of the Solution Folder in a VS project from being appended to the namespace generated for new items added to the solution folder?

Example: C# project in a VS solution Default Namespace set in C# project properties: "BigClient.Domain"

If you create a solution folder in this project called "MySpecialStuff" and then add a new class to the 'MySpecialStuff" solution folder, VS creates the new .cs file with a "BigClient.Domain.MySpecialStuff" namespace. I want to find a way to allow the namespace of the newly-added class to retain just the 'project-level' namespace of "BigClient.Domain" instead of VS appending the "MySpecialStuff" solution-folder-name to the namespace.

I seem to recall reading a blog post by someone that this was possible (either via options/settings in VS or a registry setting) but I cannot recall where or how now that I want it :)

My platform is VS 2008 if answer = different for different VS versions.

like image 458
sbohlen Avatar asked Feb 02 '09 16:02

sbohlen


People also ask

How do I change the project namespace in Visual Studio?

Just right click on the name you want to change (this could be namespace or whatever else) and select Refactor->Rename... Enter new name, leave location as [Global Namespace], check preview if you want and you're done!

Is the .VS folder necessary?

Usually, . vs folder is required by Visual Studio to store opened documents, breakpoints, and other information about state of your solution. which means It contains typical files like, Temporary caches used by Roslyn for IntelliSense.

How do I change namespace in C#?

How-to. Place your cursor in the namespace name. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Change namespace to <folder name>.

How do I automatically add a namespace in Visual Studio?

If you are adding a new class in your code then you may need to add the correspondence namespaces. To do it, you may either manually type the Using Namespace or you just right click on the class name and select Resolve > Namespace. But using “Ctrl+.” you can automatically add the namespace in your code.


1 Answers

If you have ReSharper installed, on the settings for the directory (F4), set Namespace Provider to false.

like image 113
bdukes Avatar answered Oct 05 '22 23:10

bdukes