Skip to Main Content

Monday, March 06, 2006

Visual Studio 2005 Web Deployment Options

You'll have to forgive me because I'm a little slow sometimes. But, a little while ago I noticed that my web project didn't have any .dlls associated with it whenever I compiled it. I also couldn't figure out where the bin folder was anymore. Then I thought to myself, what if I just upload the code behind file (.cs or .vb) and try to run it. It ran great. I didn't even have to compile it. Granted, it's probably smart to compile it just to make sure that there are no errors, but still.

By default, the compilation is now done on the fly, called just-in-time compilation. However, there are several different compilation options you have in 2005.

Just-in-time Compilation

As I mentioned earlier, this is the default compilation type for Visual Studio 2005. You write your .aspx page and code behind files like normal and compile to make sure there are no errors. Then, you just upload the files to your web server and voila! You're set. Not .dlls to worry about. If you need to make a change to one code behind file, make the change and upload it. It won't restart the application, it won't end all sessions, and it doesn't bog down the machine having to recompile the whole application on the first hit. However, the page needs to recompile, so when it gets called the first time, that page will take a little longer to execute so that it can compile. This seems to be the preferred way Microsoft wants us to do it now.

Pre-Compilation

Another type is In Place Pre-Compilation. The .NET framework comes with a tool called aspnet_compiler.exe located in the %WINDIR%\Microsoft.NET\Framework\v2.x.xxxx directory. There are several different parameters you can pass this tool, but when run, it will pre-compile the site for you. This pre-compiler will make .compiled files for each of your code behind files. Though there is only a slight performance advantage for the startup/compile time, it's mainly to make sure your code is free of errors.

There is also the option called Pre-compilation for Deployment. This option uses the same tool as before, the aspnet_compiler.exe tool, however we pass it the "-p" parameter and the "-v" parameter to replace all the code in the all your pages (.aspx, .ascx, .master, etc) and puts the code into one or more assemblies in the bin directory.

For a much more in-depth look at these pre-compilation option, visit the OdeToCode article, "Precompilation In ASP.NET 2.0".

VS 2005 Web Development Project

Microsoft has an add-in called Visual Studio 2005 Web Development Projects (Beta V2 Preview). This tool will offer several different compiling options, including the ability to compile to a single .dll in the bin directory like Visual Studio 2003 does. Once you download it and install it, you will have a new option available when you right click on any of your web projects. This new option is called "Add Web Deployment Project." This option is not available from the Create New Project menu. You can only add it to an existing web project by right clicking the web project in the Solution Explorer and selecting it.

Once added, right click on the new deployment project and click on the Property Pages option. You'll notice that there are four Configuration Properties to configure: Compilation, Output Assemblies, Signing, and Deployment.

Compilation

The compilation property let you dictate where your "Output Folder" will reside. This output folder holds all the .dlls generated by this tool.

You can also choose whether or not to "Generate Debug Information" when it is compiled. Since there is some overhead in generating the debug information, it is recommended to only select it if you are in a development environment. Once you release the project, it is advised that you uncheck this option.

The third option is "Use IIS metabase for source input." This specifies the full IIS metabase of the source Web site application. For example, a metabase path might be /LM/W3SVC/1/ROOT/MyWeb/, where MyWeb is the virtual directory. If there are sub-Web sites, this will result in build errors. To avoid these errors, you can specify the IIS metabase path of the Web site you are compiling, which causes the ASP.NET compiler to skip any sub-Web sites defined in the IIS metabase.

The fourth option is "Allow this precompiled site to be updatable." This is a nice feature that, if selected, will compile all your code behind files into .dlls, but will keep the HTML and server code in your .aspx and .ascx files. This is nice if you want to update the page after you compiled it without having to recompile the whole page. This is similar to the VS 2003 way of compiling. If unchecked, the HTML and server code inside of the .aspx and .ascx page will compiled into the assembly output. If you need to make an HTML change, you will need to recompile it and upload the new .dll.

Note: If you uncheck this option, you still need to have the .aspx and .ascx pages there. This is for directory structure. If you do not have it there, you will get an error saying the page does not exist. Even though the page is empty, it still has to be there! It would be nice for .NET to have something similar to Java's .war files, where you could just upload a single file that contains the whole site, but as far as I'm aware, there is nothing like that yet.

Output Assemblies

There are four different types of output assemblies you can choose when compiling.

The first is to "Merge all outputs to a single assembly." This option, combined with checking the "Allow this precompiled site to be updatable" option from the Compilation property page, will compile your web project exactly the same as Visual Studio 2003 does. This option does exactly what it sounds like; it compiles all the code behinds into a single .dll file. However, in VS 2005, you give it the assembly name.

Under this option is the "Treat as library component" check box. If checked, it will remove the App_Code.compiled file which allows you to add the App_Code.dll to another site with conflicting with the App_Code.dll assembly in the other site.

"Merge each individual folder output to its own assembly" is the second choice available. This option creates a seperate output assembly for each folder. This is nice since you can make updates to a folder and only have to recompile that folder's contents. You also have to choice to provide an "Option assembly prefix" when you choose this option. This option will prefix any name you choose (ie: MySite) to your folder's assembly output (ie: MySite.subfolder_

"Merge all pages and controls to a single assembly" is the third option in choosing what type of output assembly to create. While it sounds similar to the first option, it is different in that special folders such as App_Code, App_WebReferences, etc are each compiled into a seperate assembly.

The last option is to "Create a separate assembly for each page and control." This option compiles each page into a separate assembly. However, in doing so, it disables the compiler's batch optimizations and can result in longer compile times for larger web sites. This option is useful for granular updates of your deployed web site.

Signing and Deployment

While these are on the topic of web deployment options, they are a little out of the scope of this article. For more information, visit Microsoft's Visual Studio 2005 Web Development Projects site for more details.

0 Comments:

Post a Comment

<< Home