How do I reference a Website project

  • Thread starter Thread starter niberhate
  • Start date Start date
N

niberhate

I am working on an existing asp.net website project (not a web
application project). I want to add a unit test project to the
solution, but I don't know how to reference this website project in my
unit test project.

It is easy if it were a web application project because I could select
from the project tab. This website project does not show up in the
project tab. I am talking about the project tab in the Add Reference
dialog box.

Any idea? Thanks.
 
I am working on an existing asp.net website project (not a web
application project).  I want to add a unit test project to the
solution, but I don't know how to reference this website project in my
unit test project.

It is easy if it were a web application project because I could select
from the project tab.  This website project does not show up in the
project tab. I am talking about the project tab in the Add Reference
dialog box.

Any idea? Thanks.

Maybe it is necessary to add that my IDE is VS 2010.
 
niberhate said:
I am working on an existing asp.net website project (not a web
application project). I want to add a unit test project to the
solution, but I don't know how to reference this website project in my
unit test project.

It is easy if it were a web application project because I could select
from the project tab. This website project does not show up in the
project tab. I am talking about the project tab in the Add Reference
dialog box.

Any idea? Thanks.

You'll only be able to unit test the code in the App_Code folder and you'll
need to pre-compile the web site so that the code in this folder gets
compiled into a .dll. Then you can use the "Browse" tab of the Add
Reference dialog to browse for this .dll.

This is part of the price you pay with website projects...their code is
dynamically compiled at runtime. Microsoft and many book and article
authors like to talk a great deal about websites, but the reality is that
for large-scale mission-critical applications, ASP .NET Web Application
Projects are much preferred.

-Scott
 
You'll only be able to unit test the code in the App_Code folder and you'll
need to pre-compile the web site so that the code in this folder gets
compiled into a .dll.  Then you can use the "Browse" tab of the Add
Reference dialog to browse for this .dll.

This is part of the price you pay with website projects...their code is
dynamically compiled at runtime.  Microsoft and many book and article
authors like to talk a great deal about websites, but the reality is that
for large-scale mission-critical applications, ASP .NET Web Application
Projects are much preferred.

-Scott

So, looks like Website project is really bad for those who do TDD's.
Can we precompile the Website project and then refer to the resulting
dll outside of this Website project?
 
niberhate said:
I am working on an existing asp.net website project (not a web
application project). I want to add a unit test project to the
solution, but I don't know how to reference this website project in my
unit test project.

It is easy if it were a web application project because I could select
from the project tab. This website project does not show up in the
project tab. I am talking about the project tab in the Add Reference
dialog box.

Any idea? Thanks.

You would create a new Web application project. You remove the new
project from the 'Solution'. You right-click the Solution Name line and
select Add and Add an exiting Web site, which I will assume isa on
Localhost.

Now, you have a solution that has a project of //localhost.Website. You
can then add new projects to the solution file

But as far as you setting some kind of project reference pointing to the
//localhost.Website as a reference to another project within the
solution file is a no go -- you can't do it. You can set a project
reference in the //localhost.Website project to a project in the
solution like a classlib project.

But as far as you doing some kind of Unit or Functional test with a test
harness like MBunit, Nunit or others, you can't do that type of test
against a Web site.

You would unit test against a classlib project that was hosting a MVP or
MVC that worked with the Web UI testing against interfaces of the MVP or
MVC.
 
You'll only be able to unit test the code in the App_Code folder and
you'll
need to pre-compile the web site so that the code in this folder gets
compiled into a .dll. Then you can use the "Browse" tab of the Add
Reference dialog to browse for this .dll.

This is part of the price you pay with website projects...their code is
dynamically compiled at runtime. Microsoft and many book and article
authors like to talk a great deal about websites, but the reality is that
for large-scale mission-critical applications, ASP .NET Web Application
Projects are much preferred.

-Scott
So, looks like Website project is really bad for those who do TDD's.
Can we precompile the Website project and then refer to the resulting
dll outside of this Website project?

The only benefit of a Web Site is that you don't have to worry about all
your code having to compile into one .dll. They were invented for those
developers who wanted a finer level of granular control over the files and
assemblies in their work. But, the ramifications of using them make them
not very suitable for business application development. I don't know of any
company using them for Enterprise development. There was such a backlash
from developers when VS 2005 initially shipped without the Web Applicaiton
Project type and only the Web Site, that MS put it back into VS 2005 SP1 and
then VS 2008 and VS 2010.

If you do precompile your App_Code folder's stuff into a .dll, then you can
use the Browse tab of the Add Reference dialog to reference it from any
other project. But, if you are going to need this functionality in other
places, you may want to consider making a stand-alone class library or
component that can be used in both projects.

-Scott
 
Back
Top