VS.NET 2005: Project Namespace

Posted on 2006-04-21
Last Modified: 2013-11-19
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.
Question by:nauman_ahmed
    LVL 5

    Assisted Solution


    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
    LVL 24

    Assisted Solution

    by:DBAduck - Ben Miller
    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.
    LVL 33

    Accepted Solution

    I got an answer on from someone on the team that there is no way to automatically configure the class generation/lack of namespace creation when you create a new webform.
    LVL 33

    Expert Comment

    oh by the way, the lack of this option really sucks, IMHO!
    LVL 25

    Author Comment

    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;
        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="" %>

    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.
    LVL 33

    Expert Comment

    Spoken like a true expert!
    LVL 37

    Expert Comment

    ...just fyi....
    if it wasn't for the web application projects add in...I'd still be stuck in 2003! 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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now