Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

How do you sharing web forms and code classes across multiple projects in Visual Studio?

Hi.

I am developing multiple websites using ASP.NET in Visual Studio (using Visual Basic).
I have many clients that require a similar web site.  The core structure is the same, as well as most of the code.  However, the websites do have differences, such as image files, CSS files, a vb class that I use to store connection information.  To put it another way, there is a basic core that is shared, with particular variations in a limited number of files.

So here's the problem.  When I change the code of a core component, I want ALL websites to benefit from that enhancement.  So far I only have two websites in ASP.net, but I am converting other sites over from ASP and I may end up with as much as 10-12 websites to maintain.  I would like to not have to maintain 12 separate sites, but leverage the fact that most of the site is shared.

I have tried looking into a single solution with multiple projects, but it seems that a project is pretty much a stand-alone application, and that project files can't be used for other projects (I think).

I have also looked into deployment projects that could specify which files are part of a particular application.  But there are two disadvantages that I think would exist here:
1. I don't host my own sites and I don't have administrator priveleges on the web server (documentation states that I need this for web deployment setup).
2. I'm not sure how I would be able to develop and view one particular website without deploying it.

Any help that would get me going in the right direction would be appreciated.

0
Bconner26
Asked:
Bconner26
  • 3
  • 2
  • 2
2 Solutions
 
AerosSagaCommented:
Classes from projectX are available if you reference the projectX in projectY.  That is I have a site that requires Payment gateway processing, and shipping calculation.  So what I do is I have a moduler solution called shipping for example.  I just copy the entire solution into the new project, and add a reference to that project.  Then any public classes that I need from the shipping solution are available to me in my site by initiating a new instance of the class and then passing the paramaters to the class for the manipulation.  If you have any further questions, just ask as I know that was probably not the most concise explination.

Regards,

Aeros

0
 
ThogekCommented:
To put it another way (but basically the same as what AerosSaga is saying)....
Files/classes/etc for a given project can be used by any other projects within the same solution -- with the exception of ASCX and ASPX files.  The using project just has to add the used project as a project reference, and be sure to get the namespaces correct (if they're different) when referencing classes from the used project.  So you should be able to abstract most/all of your common logic into classes and components that can be shared by all Web projects and placing those items into their own project, and then include that project into each of the Web application project's solutions (or just load 'em all into one solution; whichever's easier for you to manage).
0
 
Bconner26Author Commented:
Thanks for the ideas concerning classes.  This will be useful to share that across projects.

However, the majority of the websites I deal with are made up of ASPX files.  This is what most of them share (both the HTML part and the code behind them).  Is there any way to share those files across projects in the way I described in the question?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ThogekCommented:
ASPX files?  I don't think so.

You may want to look into creating your own custom controls (not ASCXs) to encapsulate the reusable HTML about which you are concerned.  This loses the ability to work on the control's own HTML structure with a nice design surface for these controls (as the HTML would typically then be generated by code in a Render method), but gains the ability to be reusable across multiple projects.  (Much like the built-in ASP.NET controls such as DropDownLists, etc.)

See, e.g., http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwalkthroughdevelopingsimplewebformscontrol.asp
0
 
AerosSagaCommented:
Correct me if I'm wrong Thogek; by creating .ascx controls with the content one can gain access to the controls like so:

Dim x1 As myCustomControl = DirectCast(Me.FindControl("ReportMenu1"), myCustomControl)
                myPageLabel.text = x.MyCustomControl.Label.Text

Public ReadOnly Property GetMyLabelText() As String
 Get
   If Not Label1 Is Nothing Then Return Label1.TexT
 End Get
End Property

Regards,

Aeros
0
 
ThogekCommented:
That gains you programmatic access to the control once it's on the page, yes.  That's a little different from being able to reuse ASCX files across projects.

Some other references:
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconwebusercontrolsvscustomwebcontrols.asp
0
 
Bconner26Author Commented:
Thanks for your help.  I'll split the points.  I was able to create a project that contained classes to share across projects.  So the more code I put in classes, the more can be shared.  I'm not quite at the level of custom controls, but I'll try that sometime.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now