VS.NET 2005: Project Namespace

VS.NET 2003 has Default Namespace feature for both Windows and Web projects. In VS.NET 2005, I am unable to find it anywhere plus I am not able to reference my custom namespace. When I add a new form in VS.NET 2005, it doesnt include any namespace for the class. Anyone has idea what happened to the namespace feature and how it should be referenced in VS.NET 2005?
Thanks, Nauman.
LVL 25
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


VS.NET creates the codebehind classes without namespaces, unlike VS.NET 2003 which automatically assigned the namespace to match the directory structure rootnamespace + .subdir.subsubdir. This concept still works, you just have to remember to set up the namespaces on your own
DBAduck - Ben MillerPrincipal ConsultantCommented:
I am not sure that you can set the default namespace in the project like you could before, but 2.0 or vs2005 now includes the concept of Partial classes, so that they can hide the designer stuff behind the scenes.  So if you change the namespace in the codebehind, then VS will change the namespace to match in the designer hidden code.

I also know that VS2005 did away with Projects per se when it comes to Web Sites.  Because now we have an option of FileSystem based websites and also FTP based websites, it is no longer looked at as a project file where before there was a .vbproj and a .csproj file that kept those settings.  Now they do not exist.

Wish there was a better answer.
I got an answer on http://www.asp.net from someone on the asp.net team that there is no way to automatically configure the class generation/lack of namespace creation when you create a new webform.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

oh by the way, the lack of this option really sucks, IMHO!
nauman_ahmedAuthor Commented:
Thanks for the reply experts :)

I have found a way to reference the namespace: You have to create the namespace manually in the .cs file and then you need to use @Reference attribute for the class you want to use in the ASP.NET 2.0 web form that is located in a different folder or  has a different namesepace defined.

I usually keep my user controls, stylesheet and js in a folder called inc. So the .CS file will for header control look like the following:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace MyProject.inc
    public partial class inc_HomeHeader : System.Web.UI.UserControl
        protected void Page_Load(object sender, EventArgs e)


And ASCX file should look like this:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HomeHeader.ascx.cs" Inherits="MyProject.inc.inc_HomeHeader" %>

To reference user control Header.ascx namespace in my web site default.aspx.cs page located in the root folder, I have to add the following in default.aspx:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="inc/HomeHeader.ascx" TagName="HomeHeader" TagPrefix="Home" %>

<%@ Reference VirtualPath="inc/Header.ascx"  %>

After that, in code-behind you can continue referencing the name as it was in VS.NET 2003.

Raterus: That is absolutely true, lack of the namespace option sucks a lot. I think VS .NET 2003 was a very good development tool and Microsoft should not have taken out its functionalities in VS.NET 2005.

A side note: Since the introduction of VS.NET 2005, there were lots of issues when developers tried to port project from VS.NET 2003 since these two IDE used totally different project models. To resolve this, Microsoft has added a new project type "Web Application Projects" that uses the VS.NET 2003 web application model. More information is available at the following URL:

Visual Studio 2005 Web Application Projects (RC1)

For this update, you need to install the following:

Microsoft Visual Studio 2005 - Update to Support Web Application Projects

Visual Studio 2005 Web Application Projects Add-In

Make sure that no instance of VS.NET 2005 is running during this upgrade.

HTH, Nauman.
Spoken like a true expert!
...just fyi....
if it wasn't for the web application projects add in...I'd still be stuck in vs.net 2003!...at least my projects would have been!
here are some tutorials and walkthroughs on using it...I didn't even know that MS had anything on msdn about it...


it's buggy...but still way better than the default "migration / upgrade" tool!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.