How to Compile a Visual Web Developer Website, or ASP.NET 2.0 Site
Visual Web Developer 2005 Express Edition does not have the built-in functionality to compile (precompile)
a website or dlls. What you need to know is this - the ASP.NET Framework comes with the tools to compile
any .NET code that your write regardless of the development environment that you prefer to work in. In
fact, if you know the .NET Framework and ASP.NET syntax well enough, you can build entire websites using
only Notepad.
Deciding if you really want to precompile your site
Visual Web Developer does not provide any tools for precompiling your website. Maybe Microsoft
wants you to have to buy the retail version of Visual Studio 2005 to get
this ability? Nope, that is not the
case because compiling is built into the .NET Framework and ASP.NET itself so you
can get it for free.
So if it's not about money, why would Microsoft not want you to compile your
VWD sites? Compiling the code in
your ASP.NET website is desirable sometimes for 2 reasons. Some site owners
are concerned about the performance of their site and find that they can
get better speed with a pre-compiled site. Other developers want to sell and
distribute their software but don't want to give away all of their intellectual
property by delivering websites with source code.
If you are building a website for your company or organization using Visual Web
Developer, it is probably better to stay away from pre-compiling your site. A
content management system like VWD-CMS allows users to modify source
code that is on the web server and then ASP.NET automatically recompiles
the page the next time it is requested. To avoid making the first user of the page
wait for the page to get compiled, simply preview the page after you have finished
editing it and it will get precompiled and cached.
Creating a DLL with Code Written in VWD
To learn about compiling classes and code into a DLL, read this article:
Compiling VWD Code into a DLL.
How to Pre-compile a Visual Web Developer Website
The .NET Framework
and ASP.NET have built in tools for compiling and pre-compiling websites, all you
need to do is write a batch file to do it. After you compile your website you
just need to follow a few simple steps to deploy it to your web server.
Sample Batch File for Compiling a Website Built with VWD
This sample batch file assumes:
1. The operating system is installed on the C drive
2. You have a VWD Website project located at C:\dev\VwdSite\
3. The folder C:\dev\VwdSite\compiled exists to receive the compiled code
4. You are using the .NET Framework version 2.0.50727.
Check the computer that you are working on and make
any necessary adjustments to this script before using it.
set frmwk=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
set src=c:\dev\VwdSite
set dest=c:\dev\vwdsite\compiled
del /F /Q c:\dev\vwdsite\compiled\*.*
%frmwk%\aspnet_compiler -v /VwdSite -p %src% %dest% -c
After You Deploy the Compiled Site to the Web Server
As mentioned in the section above, there is a penalty for using a
pre-compiled site - you will not be able to make code changes on the server
using VWD-CMS or any other CMS because the code does not exist on the web
server.
ASP.NET Compiler Syntax
| |
Usage:
aspnet_compiler [-?] [-m metabasePath | -v virtualPath [-p physicalDir]]
[[-u] [-f] [-d] [-fixednames] targetDir] [-c]
[[-keyfile file | -keycontainer container]
[-aptca] [-delaySign]] [-errorstack]
|
| -? |
Prints this help text. |
| -m |
The full IIS metabase path of the application. This switch cannot be combined with the -v or -p switches. |
| -v |
The virtual path of the application to be compiled (e.g. "/MyApp"). If -p is specified, the physical path
is used to locate the application. Otherwise, the IIS metabase is used, and the application is assumed to
be in the default site (under "/LM/W3SVC/1/Root"). This switch cannot be combined with the -m switch. |
| -p |
The physical path of the application to be compiled. If -p is missing, the IIS metabase
is used to locate the app. This switch must be combined with -v. |
| -u |
If specified, the precompiled application is updatable. |
| -f |
Overwrites the target directory if it already exists. Existing contents are lost. |
| -d |
If specified, the debug information is emitted during compilation. |
| targetDir |
The physical path to which the application is compiled. If not specified,
the application is precompiled in-place. |
| -c |
If specified, the precompiled application is fully rebuilt. Any previously compiled
components will be re-compiled. This option is always enabled when targetDir is specified. |
| -keyfile |
The physical path to the strong name key file. |
| -keycontainer |
Specifies a strong name key container. |
| -aptca |
If specified, the strong-name assembly will allow partially trusted callers. |
| -delaysign |
If specified, the assembly is not fully signed when created. |
| -fixednames |
If specified, the compiled assemblies will be given fixed names. |
| -nologo |
Suppress compiler copyright message. |
| -errorstack |
Shows extra debugging information that can help debug certain conditions. |
| Examples: |
The following two commands are equivalent, and rely on the IIS metabase.
The compiled application is deployed to c:\MyTarget:
aspnet_compiler -m /LM/W3SVC/1/Root/MyApp c:\MyTarget
aspnet_compiler -v /MyApp c:\MyTarget
|
The following command compiles the application /MyApp in-place.
The effect is that no more compilations will be needed when HTTP requests are sent to it:
aspnet_compiler -v /MyApp
|
The following command does *not* rely on the IIS metabase,
as it explicitly specifies the physical source directory of the application:
aspnet_compiler -v /MyApp -p c:\myapp c:\MyTarget
|
|
|