Welcome to MSDN Blogs Sign in | Join | Help

JoeN's Blog

XNA Shaman
Default Namespace and folders

Most of my time is spent on Whidbey and Anson and I have been working on the project templates and the add item templates for Whidbey.

One of the issues we are currently looking at is the need for namespace entries in the code that gets generated when you either create a project or when you add items to a project. I'm sure that everyone has already seen the current behavior in VS 2002/2003:

  • When you create a project you get asked for the project name. We use this as the “default namespace“ for the project. All the code generated as part of the project creation gets put into this default namespace.
  • When you Add an Item to the project we generate a namespace for the code using the default namespace stored as part of the project. There's a slight twist to this, if you have added a directory to your project structure we append the directory names to the default namespace.

You can change the default namespace property in the project properties (Common Properties.General page) and you also modify the code that gets generated as part of project creation or add items by modifying the code contained at:

  • C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards

Be careful modifying the code or filenames associated with our wizards - there are JScript wizards working in the background (don't ask me why) that don't take kindly to modifications (I know from experience)

So here's the question:

Do you use the default namespace and the VS behavior to generate the right namespace entries or do you simply manually modify them after the code gets generated?

Anson and I were talking about removing the namespace declarations from the templates the other day, how would this affect you?

Posted: Monday, March 15, 2004 2:09 PM by JoeN
Filed under:

Comments

Matt Hawley said:

After modifying the default namespace in the project properties to what it needs to be, I allow the auto-populate namespace via the folder name take precedence.

So, my .02 is to leave it as it currently is, it makes sense.
# March 15, 2004 2:25 PM

Sean Chase MCSD.NET said:

I manually modify when it makes sense. Most of the time the default is good.
# March 15, 2004 2:39 PM

Luc Cluitmans said:

I never use the folder name method - I was not even aware it existed.

Instead, after creating a new project the first thing I do is change the default namespace, and manually edit the namespace in the generated source file. I would distinctly appreciate it if there was an edit box in the project creation window that allowed me to specify the default namespace explicitly.

When I want to branch out into deeper levels of namespaces, I either fix the namespaces manually, or, more often, create a separate project that has the deeper namespace as default namespace.

By the way, the paragraph in red indicates a problem in my eyes. Please add a way of easily adding, modifying, customizing the code generation wizards, that does not have the danger of messing up the VS installation. The current system is quite close to good, but underdocumented. I added a few custom wizards in my installation by simply copying existing templates and modfifying them to my liking, which is an approach that seems to work quite well.
# March 15, 2004 2:42 PM

Mike Anderson said:

I generally use the namespaces as created by default. However, I would love to have an option to create folders and NOT have objects created within them use the folder name in the namespace. For example, I like to create folders in my project for interfaces, eventargs and reports. However, I don't necessarily want them in their own namespace; I would rather they stay in the default namespace for the project.
# March 15, 2004 2:51 PM

Panos Theofanopoulos said:

I have already changed the default namespace, so new files will have the correct one (so after creating a new file i almost never alter it).

I will like (as Mike suggests) to have an option to explicity define the namespace on some folders that override the default. Specially in design time assemblies where several root namespaces exist
# March 15, 2004 3:23 PM

Michael Giagnocavo said:

+1 for leaving it alone.
# March 15, 2004 6:08 PM

Enjoy Every Sandwich said:

You have been Taken Out! Thanks for the post.
# March 15, 2004 11:29 PM

Roland Weigelt said:

- The way the "default namespace" currently works is ok.
- For me, the folder name appearing in the namespace is annoying and quite often leads to compiler errors when I forget to change edit the namespace in an added class. But this is only my personal opinion (my use of folders cannot be mapped directly to namespaces), so the best would be to offer an option to turn it off.
# March 16, 2004 12:06 AM

Omer van Kloeten said:

+1 for it being great the way it is.
# March 17, 2004 9:12 AM

sebastian said:

I agree with Mike
# March 19, 2004 9:34 AM

Red Forks said:

+1 for leaving it alone.
BTW, I more care the resource Name!
In Vs.Net 2002/2003, I can't alter the resource name prefix.
# March 28, 2004 1:20 AM

ShadowChaser said:

I strongly dislike the auto-generated "sub" namespace feature.

Once you start building a larger namespace, it becomes fairly difficult to use a single folder to contain all of the classes, structs, enums, etc that are in the namespace.

I always end up reorganizing the folders and manually editing the namespace - I found it quite frustrating at first. My folder structure is not my namespace structure :P

Given that a large number of people here are holding on to that feature - perhaps a consolation prize would be to make it an option of the project property/settings dialog? :)
# May 25, 2004 8:11 PM

Andy Brummer said:

I ran into this after renaming a project and then regenerating a web service. I was able to find the "problem" quickly.
However, I usually have to point out how the namespace is generated to new developers dealing with web references. It would be nice to have a comment next to the namespace stating where to change the value in the project.
# June 8, 2004 2:28 PM

Huthaifa Afanah said:

While I am developing a custom web control to extend the default validation summary I used some images

# October 21, 2008 9:03 AM

Huthaifa Afanah said:

While I am developing a custom web control to extend the default validation summary I used some images

# March 21, 2009 11:49 AM
Anonymous comments are disabled
Page view tracker