Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make namespace ignore certain folder C# visual studio

So I'm currently in the process of creating some Item Templates in visual studio for some commonly used classes I have to make. During this task I've run in to another problem.

I'm using folders prefixed with _ as sort of grouping folders that don't affect the namespace. However, when I create a new item in one of these folders, the _Folder is automatically appended to the workspace like so: namespace Core.Parser._Filters

Usually I would just go by hand and remove the prefixed folders from the namespace, but since I'm trying to automate this process that's no longer an option.

So I've thought of 2 ways i could solve this, but I'm not sure how they would work in practice or if they're even possible.

1) Would it somehow be possible to tell VS to exclude a folder from namespace construction? Similarly to how you can set the Build Action on .cs files to None so VS skips over them during compile.

2) Would it be possible to add a modifier to the Item Template which strips out the prefixed folders from $rootnamespace$? Something like ($rootnamespace$).Replace("._Filters", "");

like image 473
Olli Avatar asked May 11 '26 17:05

Olli


1 Answers

This will prevent Visual Studio from using the folder name as part of the namespace (if ReSharper is installed):

Right-click on folder -> Properties -> NamespaceProvider = false

like image 88
richej Avatar answered May 13 '26 09:05

richej