?
Solved

VS.NET 2005: Project Namespace

Posted on 2006-04-21
7
Medium Priority
?
4,763 Views
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.
0
Comment
Question by:nauman_ahmed
7 Comments
 
LVL 5

Assisted Solution

by:razorback041
razorback041 earned 600 total points
ID: 16510142

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
0
 
LVL 25

Assisted Solution

by:DBAduck - Ben Miller
DBAduck - Ben Miller earned 600 total points
ID: 16510446
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.
0
 
LVL 33

Accepted Solution

by:
raterus earned 800 total points
ID: 16510754
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.

http://forums.asp.net/thread/1209332.aspx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 33

Expert Comment

by:raterus
ID: 16510769
oh by the way, the lack of this option really sucks, IMHO!
0
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 16511209
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.
0
 
LVL 33

Expert Comment

by:raterus
ID: 16511285
Spoken like a true expert!
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 16512137
...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!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
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.
Suggested Courses

850 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