Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET
Article

Easy way to compile Web Projects to multiple assemblies

Rate me:
Please Sign up or sign in to vote.
2.59/5 (5 votes)
26 Apr 20044 min read 49.2K   435   13   4
Ever wished to compile a web to multiple <i>.dll</i>s?

Introduction

Ever wished to compile a web project into multiple assemblies?

When you are working with web projects in Visual Studio and compile them, the result is, all your code-behind classes compiled into one single big assembly. This is fine as long as the web application is small and the development team is small (read 1). But like me, if you are involved with the development of a pretty large and dynamic web application with a medium-sized development team, then you probably know that compiling everything to a single assembly is a deployment hell. This is, of course, not due to the fact that the web application is in a single file but due to the fact that no one can be really sure of what that DLL is containing. Even if any type of source control is used, like Source Safe, it's near to impossible to determine what's in (or out) of the final build before production.

So, because of this, and because of the great support of compiling at runtime in the .NET framework 1.1, I decided to at least build some kind of demo project that could easily split up a project into the number of assemblies I found appropriate. If that means one .dll per aspx, then so be it!

Disclaimer

The sample code provided is a demonstration-project. Use it with care.

Project limitations

The project at this point is only capable of parsing and compiling Visual Basic Web Projects, it should be straightforward to modify the code in order to make it work with C# Web Projects. Unfortunately, I have not got the time to do this right now, so feel free to contribute.

Probably, the modifications needed is only in 4 functions, Make(), Makebatch() to run with C# compiler, dragAndDrop(), and OpenFile() function to allow .csproj-files to be opened.

Project capabilities

The project is capable of parsing and compiling Visual Basic Web Projects into an arbitrary number of DLLs. What that means is you can use this program to compile every code-behind file to its own, atomic if you will call it, .dll. So, when moving from development to production environment, you will be sure of what pages are updated and what pages are new.

The project is also capable of grouping and compiling source files to bigger assemblies, and even to compile like Visual Studio, to one great all-included assembly.

The Visual Studio Web Project file

Visual Studio uses XML files to hold project information. These are typically named after your web application, like Webapplication1.vbproj. If you open these type of files with Notepad instead of Visual Studio, you can see all the information about your project in marked up text.

Parsing the project file

I use seven classes to represent a .vbproj XML file. These are:

  • VSWebProject
  • CReferences
  • CReference
  • CImports
  • CImport
  • CFiles
  • CFile

This is not a correct way in an academic sense but it's good enough for this project in the state it's in right now.

I am not going to make any comment on the source code yet. And it's pretty straightforward, so I do not see the need for it at this point.

The classes above are populated when parsing the .vbproj file with XmlDocument, and when done, project properties can be reached programmatically.

When the project file is parsed, the UI is set up with the properties of the project. That means, you will get lists of referenced assemblies, imported namespaces, paths and so on, i.e., all information necessary to compile.

You will be given the possibility to change/add/delete all important properties via the GUI.

The GUI

It is self explaining.

Getting started

Download the source files and compile them, run the application. If you don't have Visual Studio, simply cut and paste the lines below (remember to paste the text on the same line!) and run it from a command prompt in the folder where you unzipped the source files, and you will get an executable file called VSMaker.exe:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc
/target:winexe /rootnamespace:VSMaker /r:System.Windows.Forms.dll
/r:System.Data.dll /r:System.Drawing.dll /r:System.dll /r:System.Xml.dll
/imports:System /imports:Microsoft.VisualBasic /imports:System.Collections
/imports:System.Data /imports:System.Drawing /imports:System.Diagnostics
/imports:System.Windows.Forms /imports:System.Windows.Forms.Form
/resource:Form1.resx /main:VSMaker.Form1 /out:VSMaker VSWebProject.vb
CFile.vb CFiles.vb CImport.vb CImports.vb CReference.vb CReferences.vb
Form1.vb AssemblyInfo.vb

(Check which version of .NET framework you have installed and change v.1.1.4322 to your version)

You open a project file via the menu (File->Open project), or just drag & drop a project file on the form.

Under the "files" panel, check the files that you wish to compile and press the "Build!" button. If your references and imports are OK, your files will be compiled to a subfolder in your web project's folder, called bin_VSMaker. You can also choose any output directory you wish under Configuration Properties->Build.

If you wish to group your selected files into one assembly, just check Group files and choose an assembly name.

Errors during compile

If your files didn't compile, you should view the error description under the Build panel, that was produced by vbc.exe. Be sure to check your reference paths and imported namespaces.

Conclusion

It was surprisingly easy to create this project. It makes one wonder why MS did not release a VS add-in or something like that to achieve the same thing?

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Sweden Sweden
Been working as a software developer since 2000, programming since 1985, first publish in a swedish magazine 1987.

Comments and Discussions

 
GeneralSo... Pin
Daniel Turini27-Apr-04 7:50
Daniel Turini27-Apr-04 7:50 
GeneralRe: So... Pin
c98mpn27-Apr-04 11:08
c98mpn27-Apr-04 11:08 
QuestionAre you like me? Pin
Anonymous27-Apr-04 7:41
Anonymous27-Apr-04 7:41 
AnswerRe: Are you like me? Pin
Eric Engler18-May-04 11:46
Eric Engler18-May-04 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.