|
-
Jan 12th, 2011, 05:46 AM
#1
Thread Starter
Fanatic Member
Difference Project and Web Site
What is the difference between a Project and a Web Site. In Visual Studio it offers File | New Project ... and File | New Web Site
As what I develop are going to be web sites, I choose File | New Web Site
But ... I have a number of web sites that all access the same database and within each web site I have a lot of duplicated functionality - like GetContact(int ContactID), GetNotes(int JobID) etc. etc.
Can I keep all the common code in one place and access it from each web application? I have the idea that this is what a 'Solution' is for, with the ability to add various Projects to a Solution.
But, if you create a web site (as opposed to a project) you don't seem to be able to reference another project. Can you?
Thanks for any help.
Last edited by Webskater; Jan 14th, 2011 at 03:31 PM.
-
Jan 12th, 2011, 09:44 PM
#2
Re: Difference Project and Web Site
Hello,
The difference is that one uses the Web Application template, and the other uses the Web Site template. You can find information about the differences here:
http://www.c-sharpcorner.com/UploadF...M/website.aspx
Typically, I always use a Web Application.
You have the option of creating a class library prokect and putting all the common code in there, and referencing this class library in each of your web applications.
Gary
-
Jan 13th, 2011, 05:14 AM
#3
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by gep13
Hello,
The difference is that one uses the Web Application template, and the other uses the Web Site template. You can find information about the differences here:
http://www.c-sharpcorner.com/UploadF...M/website.aspx
Typically, I always use a Web Application.
You have the option of creating a class library prokect and putting all the common code in there, and referencing this class library in each of your web applications.
Gary
Thanks for that. Please bear with me on this - I have created a 'Class Library project' which has a single .cs file in it with a namespace of ClassLibrary1.
The only 'build' option is 'build'. Having used VB a bit in the past, I was expecting to be able to build a dll and reference that from other projects. But I can't see how to do that.
So, now my question is ... how can reference ClassLibrary1 from other projects?
Thanks again for the help.
-
Jan 13th, 2011, 08:16 AM
#4
Re: Difference Project and Web Site
Once you have built the DLL... from the OTHER project, right-click on the project in the solution explorer, and select Add Reference (not Add Web Reference... that's different) ... you'll get the references dialog. From there select the "Browse" tab, and then browse to where you built the DLL at... select it, and click OK (or add referrence, or what ever the afirmative button is... to be honest, I just click it and never really paid attn to what it says... but I digress) ... that will add the DLL as a reference in your project.
-tg
-
Jan 13th, 2011, 08:23 AM
#5
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by techgnome
Once you have built the DLL... from the OTHER project, right-click on the project in the solution explorer, and select Add Reference (not Add Web Reference... that's different) ... you'll get the references dialog. From there select the "Browse" tab, and then browse to where you built the DLL at... select it, and click OK (or add referrence, or what ever the afirmative button is... to be honest, I just click it and never really paid attn to what it says... but I digress) ... that will add the DLL as a reference in your project.
-tg
Thanks for your reply ... sorry, I wasn't very clear - the bit I'm stuck on at the moment is ... how do you build the dll?
I read if you 'build' the project it will create a dll. It doesn't when I build the project - as far as I can see - nothing happens.
I have read elsewhere you have to build the dll from a 'command line' - is this true? Seems very old fashioned if it is.
-
Jan 13th, 2011, 08:29 AM
#6
Re: Difference Project and Web Site
I read if you 'build' the project it will create a dll. It doesn't when I build the project - as far as I can see - nothing happens.
Are you sure? How do you know? I get angels singing Hallelujah, but that's because I've got the DanBrown add-in. (you don't want to know what happens when the build fails with that add-in) What is it you are expecting to see happen? Look in the bin/debug folder (or the bin/release one) ... if necessary, select the project in the solution explorer, and click the "Show All Files" button in the explorer's toolbar...
-tg
-
Jan 13th, 2011, 08:43 AM
#7
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by techgnome
Are you sure? How do you know? I get angels singing Hallelujah, but that's because I've got the DanBrown add-in. (you don't want to know what happens when the build fails with that add-in) What is it you are expecting to see happen? Look in the bin/debug folder (or the bin/release one) ... if necessary, select the project in the solution explorer, and click the "Show All Files" button in the explorer's toolbar...
-tg
Okay, that worked! Didn't realise the bin could be hidden. There was a dll there and I have referenced it okay from another project. I can hear angels singing 'Hallelujah' - and that's without the add-in!
Do I need to worry about registering / unregistering dlls when I rebuild the library project as I add new functions to it?
When I rebuild the dll do I need to update the references to it in other projects or does this happen automatically?
Thanks for the help on this.
-
Jan 13th, 2011, 09:17 AM
#8
Re: Difference Project and Web Site
no... you don't need to worry about registering the dll... that's the beauty of .NET... it's no longer necessary to register dlls. You just need to make sure it is in the app folder when you deploy. By default, referenced DLLs should be copied to the bin/Debug|Release folder, so if you just copy everything (skip the XML and PDB files) to the destination, then you should be good.
-tg
-
Jan 13th, 2011, 09:55 AM
#9
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
-
Jan 13th, 2011, 09:56 PM
#10
Re: [RESOLVED] Difference Project and Web Site
Also, bear in mind that if you do use the Web Application Template, you can add the Class Library Project to the solution. That way you don't have to reference the built DLL directly, but rather create a reference to the Class Library Project.
Gary
-
Jan 14th, 2011, 03:28 PM
#11
Thread Starter
Fanatic Member
Re: [RESOLVED] Difference Project and Web Site
 Originally Posted by gep13
Also, bear in mind that if you do use the Web Application Template, you can add the Class Library Project to the solution. That way you don't have to reference the built DLL directly, but rather create a reference to the Class Library Project.
Gary
I did this... (in VS 2005 on machine at home) ...
File | New | Project
and then, under Visual Studio Installed Templates, I selected
ASP.Net Ajax Enabled Web Application
Below that part of the window it showed:
Solution: with a drop-down list that showed 'Create New Solution'
Having created the project (solution?) (which is called AjaxEnabledWebApplication1), if I right click on the name of the project at the top of the Solution Explorer - one of the items available is 'Convert to web application'. This puzzles me, I thought I had just created a 'web application'.
But, what I can't see is how to add another project (the Class Library one) to the Solution.
On other machines I have seen people with a Solution that has 3 or 4 projects in it? How do you get those projects into the solution?
Thanks again.
-
Jan 14th, 2011, 04:19 PM
#12
Re: Difference Project and Web Site
Right click on the solution iteself in the solution explorer (NOT the project node... but the solution) and select Add -> Existing (or new) Project...
The default setting in VS is to hide the solution when there is only one project in it. To get around this you can Add Project from the File menu... or go into the Option screen, and find the "Hide Solution" option and turn it off.
-tg
-
Jan 14th, 2011, 09:01 PM
#13
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by techgnome
Right click on the solution iteself in the solution explorer (NOT the project node... but the solution) and select Add -> Existing (or new) Project...
The default setting in VS is to hide the solution when there is only one project in it. To get around this you can Add Project from the File menu... or go into the Option screen, and find the "Hide Solution" option and turn it off.
-tg
Ahhh, slowly, after 3 years of using Visual Studio, the penny begins to drop!
I've added my ClassLibrary1 project to my AjaxEnabledWebApplicationProject1 ... added a reference to ClassLibrary1 project and, abracadabra, I can stick 'using ClassLibrary1' (which is the namespace) at the top of a page and then instantiate the class in ClassLibrary1 and access its methods etc.
Suddenly I think I'm beginning to understand this stuff.
While we're on this subject ... my 'AjaxEnabledWebApplicationProject1' has some automatically added references ... like System.Data and System.Drawing.
If the project has a reference to System.Data - why do I have to put 'using System.Data' at the top of every page?
I use, for example, System.Data.SqlClient on almost every page. Is there any way of adding this to the project once - so I don't have to remember to include it at the top of every page.
If I click 'Add Reference' - under .Net it lists System.Data (amongst loads of others). Why doesn't it list System.Data.SqlClient?
Thanks again for your help - and to Gary - I'm finally beginning to get this stuff. Despite reading and working my way through a 688 page book on creating ASP.NET web sites - and reading various tutorials - I found nothing about how to create solutions with multiple projects to make sure you re-use code and don't write it over and over again in different projects - at least nothing that was written in plain English.
Likewise the book I read was full of examples of writing sql in the code behind to populate grids etc. - nothing about creating a Data Access class - nothing about creating middle tier objects - nothing about only ever allowing access to your database via stored procedures. Fortunately I already knew a bit about that so I didn't make those mistakes.
-
Jan 14th, 2011, 09:26 PM
#14
Re: Difference Project and Web Site
Hey,
Adding a reference to the assembly basically gives Visual Studio access to the namespaces and classes within the Assembly, however, in order to access them, you have to tell Visual Studio what sections of that assembly that you want to use. This is where the use of the using statement comes in.
You either need to explicitly declare the class that you want to use, i.e.
Code:
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
or:
Code:
using System.Data.SqlClient
...
SqlConnection connection = new SqlConnection();
If you "always" use this namespace (System.Data.SqlClient), then you should be able to alter the default class template that Visual Studio uses, but this isn't something that I have ever felt the need to do, I simply add this as and when required.
Gary
-
Jan 15th, 2011, 04:56 AM
#15
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by gep13
Hey,
Adding a reference to the assembly basically gives Visual Studio access to the namespaces and classes within the Assembly, however, in order to access them, you have to tell Visual Studio what sections of that assembly that you want to use. This is where the use of the using statement comes in.
You either need to explicitly declare the class that you want to use, i.e.
Code:
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
or:
Code:
using System.Data.SqlClient
...
SqlConnection connection = new SqlConnection();
If you "always" use this namespace (System.Data.SqlClient), then you should be able to alter the default class template that Visual Studio uses, but this isn't something that I have ever felt the need to do, I simply add this as and when required.
Gary
But ... just to labour the point ... I have a few projects that I created as web sites. In the Solution Explorer there is no 'reference' to 'References' - but there is an App_Code folder and an App_Data folder.
Looking at the web application I created yesterday, there is a 'References' folder and a 'Properties' folder with AssemblyInfo.cs inside it (but no App_Code and App_Data folders)
This 'References' folder contains references to:
System
System.Data
System.Configuration
System.Drawing
etc.
In the web application project if I put this:
string connectionString = ConfigurationManager.ConnectionStrings["MMPConnectionString"].ConnectionString;
on a code behind page without 'using System.Configuration' at the top of the page' - it falls over ... 'are you missing an assembly reference?'
So, what's the point of the reference to System.Configuration in the 'References' folder if you still have to write 'using System.Configuration' at the top of every page on which you want to access methods in the System.Configuration namespace?
-
Jan 15th, 2011, 11:55 AM
#16
Re: Difference Project and Web Site
The using key word is a SHORTCUT... When you used ConfigurationManager, the IDE has no way of knowing where it is... what if you have TWO classes that define ConfigurationManager? W/o the uses, you MUST use the fully qualified name (FQN) System.Configuration.ConfigurationManager.ConnectionStrings["MMOConnectionString"].ConnectionString .... After a while, that becomes a hassle... so MS gave use the Uses (or Imports in VB) So that we can say "hey, we're using this namespace, so look for references starting at this level" ...
Think of the namespaces like an office building. You're trying to deliver a package to some coimpany up on the thrid floor... only all you have is the address of the buiklding and hte name of the company... w/o any other clue, all you can do is wander about the first floor. When you're unable to find the company, you return to the truck and report that you were unable to find the reference. The Using is like the building's floor directory... it tells you the company you're looking for is on the thrid floor, and so you're able to then succdessfully find it and deliver the package.
-tg
-
Jan 15th, 2011, 12:12 PM
#17
Re: Difference Project and Web Site
Hello,
I feel I should point out, that even with a Web Site Project, you can still add a reference, it is just that there isn't an explicit "folder" for them in the solution explorer. If you right click on the Web Site root node in solution explorer, you can still choose to "Add Reference". Also, if right click on the Web Site and choose "Property Pages" you will see all the references that you have in your web site.
I should stress that although the IDE handles the references differently in a Web Site Project compared to a Web Application Project, the essence is the same. You are creating a reference to an assembly that has code within it that you want to use in your current project.
To extend slightly on tg's point...
I typically always use a using statement at the top of my class, but there are some cases where you "have" to explicitly reference a type. The reason behind this is that the same type name might exist in multiple namespaces. If you try and use the "shorthand" way of referencing the type, Visual Studio won't know which one you are referring to, as there are two. In that case, you either need to remove the "using" for the one you don't want (although this isn't always possible as you may be using other types within that namespace), or you explictly define the type.
Gary
-
Jan 15th, 2011, 12:19 PM
#18
Re: Difference Project and Web Site
 Originally Posted by techgnome
Think of the namespaces like an office building. You're trying to deliver a package to some coimpany up on the thrid floor... only all you have is the address of the buiklding and hte name of the company... w/o any other clue, all you can do is wander about the first floor. When you're unable to find the company, you return to the truck and report that you were unable to find the reference. The Using is like the building's floor directory... it tells you the company you're looking for is on the thrid floor, and so you're able to then succdessfully find it and deliver the package.
-tg
Nice analogy
-
Jan 15th, 2011, 12:43 PM
#19
Re: Difference Project and Web Site
I'm not sure about in C#, but in VB, you can alias your imports too... We used this alot around the Infragistics namespaces since so many are burried many layers deep. It also meant that when we came across a reference and we see UWG.GridRows ... we knew that that was an UltraWebGrid namespace object. Comes in handy when dealing with naming collisions you mentioned - and you still get the benefit of not having to use the FQN.
-tg
-
Jan 15th, 2011, 02:49 PM
#20
Re: Difference Project and Web Site
Hey,
Thats a good point. You can do the same thing in C#.
The format is:
Code:
using SW = System.Web;
Then you can do:
Gary
-
Jan 15th, 2011, 03:31 PM
#21
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
Thanks again for your replies.
I understand the 'namespace' concept and that without putting using System.Data.SqlClient you can't, for example, just write:
SqlDataReader dr = whatever
on the page.
What I still don't get is this:
In my Web Application Project there is a 'folder' called references and System.Data is referenced. And, as has been pointed out, I still need 'using System.Data' at the top of any page where I want to access what's in that namespace.
In a Web Site Project I just looked at the References on the Property Pages and 'System.Data' is not referenced. Yet I can put 'using System.Data' at the top of the page and access the namespace with no problems. So, how come the 'Web Site Project' doesn't need a reference to System.Data? (No mention in web.config either)
-
Jan 15th, 2011, 05:37 PM
#22
Re: Difference Project and Web Site
Hey,
I don't know this for a fact, perhaps tg can offer something here, but I "think" there are some built in references for certain project types. That way, you don't explicitly have to reference System.Data, as it already has a reference.
Actually, if you try to add a reference to the System.Data assembly, you will actually get an error saying that it is already referenced.
Gary
-
Jan 15th, 2011, 06:13 PM
#23
Re: Difference Project and Web Site
Gary's correct... some project templates ... and that's what all those projects are are just templates ... have different settings. One of those types of settings is default references. There really isn't a project that doesn't use System.Data, so it's pretty much added to every single project type out there. What's happening is that the reference is being automatically included because it's such a basic need.
-tg
-
Jan 15th, 2011, 06:28 PM
#24
Re: Difference Project and Web Site
tg, I was trying to find a link to somewhere that mentioned what those default references are, but I couldn't find one. Are you aware of one?
Gary
-
Jan 15th, 2011, 07:11 PM
#25
Re: Difference Project and Web Site
No... there isn't a list that I am aware of. It's just one of those things that kind of happens, and when you run into it, it makes sense... like when you add a Class Library... it doesn't have the Windows.Forms namespace loaded by default... which makes sense.,.. why wouyld you need forms in a class library.
I did try an experiment though... because I was curious... I created a Web Site Project... opened the property pages. Sure enough System.Data wasn't listed. OK... so I added a class file, and added "Imports System.Data" to the top (I was in VB mode at the time) ... no errors. So far so good. Then I right click the project and selected "Add Reference" ... found System.Data and added it as a reference. No errors. OK, so far so good. Went back to the References Property Page.... and it's still not listed.
Conclusion: Web Site projects don't follow the same rules as other projects. References and how they are displayed are different. In the grand scheme of things it's not very importaint. It may be that it's not listed to prevent someone from accidentally removing it. I don't know. I did notice that when I added a class file, the IDE yelled at me because I had tried to put it in the main folder and not the app_code folder. And the Property Page for the WS Project is different from the traditional Project Properties view.
Corollary Conclusion: Web Site Projects are a breed unto their own.
-tg
-
Jan 15th, 2011, 07:14 PM
#26
Re: Difference Project and Web Site
 Originally Posted by techgnome
I did try an experiment though... because I was curious... I created a Web Site Project... opened the property pages. Sure enough System.Data wasn't listed. OK... so I added a class file, and added "Imports System.Data" to the top (I was in VB mode at the time) ... no errors. So far so good. Then I right click the project and selected "Add Reference" ... found System.Data and added it as a reference. No errors. OK, so far so good. Went back to the References Property Page.... and it's still not listed.
What version of VS are you using? I am using 2010, and when I did this (granted in a CS Web Site), Visual Studio actually gave me an error saying that is was already referenced. But it wasn't listed in the Property Pages.
 Originally Posted by techgnome
Corollary Conclusion: Web Site Projects are a breed unto their own.
Agreed. One of the many reasons why I tend not to use them at all.
Gary
-
Jan 15th, 2011, 08:52 PM
#27
Re: Difference Project and Web Site
I was using VS2008. I find it to be faster for smaller one-off tests like this. It's possible that was an "enhancement" in VS2010 ... people complaining that their references weren't being added (???)
-tg
-
Jan 16th, 2011, 11:14 AM
#28
Re: Difference Project and Web Site
I have just done a test in Visual Studio 2008, and I get the same as you. It must have been an "enhancement" in 2010 to indicate that the reference is already referenced.
Gary
-
Jan 20th, 2011, 07:01 AM
#29
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
I have used a control from an external supplier which is a textbox with html formatting - like the box I am typing in now.
I have endless problems with deployment and the licenses file ... one of the things the help files indicate is that you must 'Rebuild the project (not the solution)'
How do you 'rebuild' a web site project (as opposed to application)? The build menu only has 'Build' and 'Publish' on it.
-
Jan 20th, 2011, 07:53 AM
#30
Re: Difference Project and Web Site
So select Build... rebuild is just simply a forced build all ... while Build will typically only build changed components.
-tg
-
Jan 20th, 2011, 08:02 AM
#31
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by techgnome
So select Build... rebuild is just simply a forced build all ... while Build will typically only build changed components.
-tg
Thanks for the Reply. What's the point of Rebuild then?
-
Jan 20th, 2011, 08:13 AM
#32
Re: Difference Project and Web Site
Like I said... it's a Forced Build All. ... in other words, rebuild EVERYTHING whether it's changed or not. Sometimes it's necessary.
-tg
-
Jan 20th, 2011, 05:38 PM
#33
Re: Difference Project and Web Site
Out of interest, which HTML Textbox are you using?
There are a number of good ones out there.
By the way, you can specifically right click on an individual project, and select build, rather than the solution file, and it will only build the application, and any dependent projects, if required.
Gary
-
Jan 20th, 2011, 06:50 PM
#34
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by gep13
Out of interest, which HTML Textbox are you using?
There are a number of good ones out there.
By the way, you can specifically right click on an individual project, and select build, rather than the solution file, and it will only build the application, and any dependent projects, if required.
Gary
It's the Dart PowerWeb HTML TextBox.
-
Jan 21st, 2011, 08:02 AM
#35
Re: Difference Project and Web Site
-
Jan 21st, 2011, 08:15 AM
#36
Thread Starter
Fanatic Member
Re: Difference Project and Web Site
 Originally Posted by gep13
Yes, I found that freetextbox one a few days ago. Have to say I like it. Dead easy to use - just download the dll and reference it and off you go.
$44 for a license to get the version with 'clean up data pasted from Word' included.
We paid a few hundred bucks for the Dart one I seem to recall. Never liked it - slow to appear on the page if you leave all the buttons on there too.
-
Jan 22nd, 2011, 04:07 PM
#37
Re: Difference Project and Web Site
Shame! Hindsight is a wonderful thing!
At least you will know about it for your next project.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|