views:

2222

answers:

4

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.

+4  A: 

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

bdukes
don't seem to see that anywhere -- you mean the properties for the solution folder itself in VS? Only property listed is 'Folder Name' (which, of course, is the name of the folder itself)
sbohlen
Ah, nevermind. I guess that's a ReSharper setting, not built into Visual Studio
bdukes
+1  A: 

Make a new class template or change Visual Studio's class template. See the MSDN documentation for how to this. In the template file you quickly see the line that inserts the 'safe' namespace name.

I'm not sure how this is the accepted answer. It doesn't answer the OP's original question. http://msdn.microsoft.com/en-us/library/eehb4faa%28VS.80%29.aspx lists all of the built-in template parameters and there appears to only be on parameter, $rootnamespace$ that has anything to do with namespaces, and that $rootnamespace$ appears to always include the folder name that the file is being added into. This is what the OP was hoping to eliminate.
Yoopergeek
A: 

I don't have ReSharper, and am actually having the opposite problem in VS2008: I want the nested folder names to be appended to my namespace, but Visual Studio won't do it. I create a project at ...\Documents\Visual Studio 2008\Projects\Folder1\Folder2\ProjectName or whatever, and I want the namespace to be like Folder1.Folder2.ProjectName, but it VS always makes it match the plain project name.

I've found one workaround which is to name it like \Folder1\Folder2\Folder1.Folder2.ProjectName\Folder1.Folder2.ProjectName.csproj etc. but that's pretty ugly.

East of Nowhere
A: 

If you have resharper:
Right click on folder (in solution explorer) and change "Namespace Provider" to false.

Another way is to play with templates that generating the new classes.

Avram
Only works if you have ReSharper installed. See bdukes answer, above.
Robert Harvey