roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Do not include folder name to namespace

Open vsfeedback opened this issue 4 years ago • 5 comments

This issue has been moved from a ticket on Developer Community.


When a new class is created under a folder, Visual studio automatically appends the folder name to the namespace. This is very difficult to catch in codereviews and in some common libraries changing this later becomes extremely hard.

Please provide an easy way to disable this in csproj.


Original Comments

Visual Studio Feedback System on 6/23/2020, 00:34 AM:

We have converted this feedback item from problem to idea. This change was done to better reflect the feedback's nature.

Visual Studio Feedback System on 6/24/2020, 02:55 AM:

Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.

vsfeedback avatar Jun 26 '20 22:06 vsfeedback

How I would like to see this implemented:

  1. Add an Include in Namespace boolean property to folders that indicates whether the folder is purely for organizational purposes or should be reflected in the namespace of classes or interfaces created in that folder. Default this to true since that is the current behavior.
  2. When adding a new class or interface to a folder, if the Include in Namespace property is set to false, do not include that folder name as part of the namespace.
  3. If a folder has Include in Namespace set to false, show it as a different color so that visually you can easily identify which folders are part of the namespace, and which are not, when looking at the structure in the solution explorer.
  4. Update the context menu/folder creation options to include New namespace folder and New organizational folder to allow for direct creation of the specific type of folder you want without having to manually tweak the settings on that folder.

KirkMunro avatar May 04 '21 12:05 KirkMunro

I would like this feature. I think all that is necessary is an option on the folder in the properties tab that turns it off (thus skipping this folder as a part of namspace naming). This would also be the default option for sub-folders of a folder with it off.

hamarb123 avatar Dec 30 '21 07:12 hamarb123

Is there not an option to disable this at the project level? This is extraordinarily irritating for those of us that do not used folders as namespaces.

Ziflin avatar Aug 10 '22 15:08 Ziflin

I don't believe there is. This appears to represent a small minority position. We'll have to weigh the cost of doing this, versus everything else, versus the size of the ecosystem that benefits from it.

CyrusNajmabadi avatar Aug 10 '22 15:08 CyrusNajmabadi

Related: https://github.com/dotnet/project-system/issues/5372

davidwengier avatar Aug 10 '22 22:08 davidwengier

I would like to see this too, in smaller projects, it sometimes makes sense to organize files into folders, but use one namespace for all objects.

Balkoth avatar Dec 06 '22 10:12 Balkoth

I would like to see this too, in smaller projects, it sometimes makes sense to organize files into folders, but use one namespace for all objects.

example: Organizing models in a meaningful folder structure that does not participate in namespace naming but keeps them all in the Models namespace.

CodeAngry avatar Jan 25 '23 22:01 CodeAngry

I don't believe there is. This appears to represent a small minority position. We'll have to weigh the cost of doing this, versus everything else, versus the size of the ecosystem that benefits from it.

I don't think this represent a small minority. JetBrains Rider provided an option for this in a much more sophisticated way. Frankly if I can afford it, I will ditch Visual Studio with no hesitation. All you need to do is to provide a boolean option in the Solution Explorer's Folder Properties, say NamespaceProvider that determines whether the folder name will be included in the namespace or not.

justinefication avatar Jan 26 '23 03:01 justinefication

@aLexiusxx this is on our backlog. So if you wanted to contribute the fix of "All you need to do is...", We would likely take it. Thanks!

CyrusNajmabadi avatar Jan 26 '23 04:01 CyrusNajmabadi

I've wanted this for 20 years. Maybe it'll happen after I retire. It has just never made sense for a namespace to be tightly coupled to a file's location in a filesystem. They have dick-all to do with one another. All I want is for a new file to always just have a single namespace that is specified in the .csproj file. That would solve it for 95% of us.

FacioRatio avatar Apr 05 '24 21:04 FacioRatio

@FacioRatio see https://github.com/dotnet/roslyn/issues/45494#issuecomment-1404544494.

CyrusNajmabadi avatar Apr 05 '24 21:04 CyrusNajmabadi