Link to home
Start Free TrialLog in
Avatar of nauman_ahmed
nauman_ahmedFlag for United States of America

asked on

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.
SOLUTION
Avatar of razorback041
razorback041
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of DBAduck - Ben Miller
DBAduck - Ben Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh by the way, the lack of this option really sucks, IMHO!
Avatar of nauman_ahmed

ASKER

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)
http://msdn.microsoft.com/asp.net/reference/infrastructure/wap/

For this update, you need to install the following:

Microsoft Visual Studio 2005 - Update to Support Web Application Projects
http://www.microsoft.com/downloads/details.aspx?FamilyId=8B05EE00-9554-4733-8725-3CA89DD9BFCA&displaylang=en

Visual Studio 2005 Web Application Projects Add-In
http://download.microsoft.com/download/4/5/8/45854188-5E47-4E7C-A865-16397D8DD78E/WebApplicationProjectSetup.msi

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

http://webproject.scottgu.com/

it's buggy...but still way better than the default "migration / upgrade" tool!