Asp.net 2.0 Compilation Models

posted on Saturday, July 05, 2008 8:29 AM

Keep the following in mind with 2.0 Asp.net applications

  • Visual Studio 2005/2008 knows nothing about compiling a web application.  Visual Studio lets the asp.net platform perform the compilation.
  • When you perform a VS.NET Build > VS.NET does not build the application, Asp.net performs the build build of all the .cs and .vb files.  The resulting assemblies are placed by default in the C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files directory.
  • The debug setting in the web.config (debug/release) controls the compilation mode.  If in debug mode then respective .pdb debugging symbol files are created.
  • The Configuration Manager in the default build model of Visual Studio is not utilized.  As a result the only option for a web site ‘project’ is the Debug compilation.  This is because the web.config controls the compilation.
  • The Publish command will precompile the web application and place the files in a directory for deployment.  The Publish command executes the command line aspnet_compiler tool with the appropriate switches.  Publish will always precompile a release build without debugging symbols (pdb files)
  • Note: the Publish command does not change the debug setting in the web.config.  The Publish command always compiles in release ode however if you precompile to an updateable web site and then update the web site in place those dynamic compilations will produce debug code and pdb files.

Using the Web Site Deployment Utility (WSD)

Using WSD the above scenario is different.  Web Site Deployment project is really a nice interface on a MSBuild project.  The deployment project creates a MSBuild file and passes it to aspnet_compiler for compilation.  Unlike the VS.NET Publish the WSD will update the web.config for the right compilation mode.  The user controls the compilation mode within the Configuration Manager when using the Web Site Deployment project.

Setting up Configuration Manager as follows will deploy the files to the directory highlighted below without debug symbols (debug=false).  By setting up the configuration as follows makes it easy to prepare for deployment.  Simply change the configuration mode and hit build.  As shown below it will simply prepare the application for build and asp_compiler will deploy to the selected directory. 

In addition to controlling the debug mode WSD is great for swapping out appsettings for different environments (i.e. stage/test/production) respective for each build.


 image 

Control the deployed directory via Properties of the WSD project.

image


By debug mode will look like the following.  Notice that I am not building the WSD project in this mode

image

More information and features of Web Site Deployment Project can be found here.

 

Additional Configuration of the MSBuild file

By selecting the deploy project in the Solution Explorer and selecting open you can add additional MSBuild commands to the xml document.  I often add the following so that only the most appropriate files are included in the Release directory.

<ItemGroup>
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.vshost.exe" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.sln" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.csproj" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.user" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*Copy of*" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.psd" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.cmd" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\obj\**\*.*" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.Publish.xml" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\test\**\*.*" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.aspx.resx" />
    <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.asax.resx" />
      <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.suo" />
  </ItemGroup>

 
 
    <Target Name="AfterBuild">
        <Delete Files="$(OutputPath)\PrecompiledApp.config"></Delete>
    </Target>
category: Asp.Net

Comments


# re: Asp.net 2.0 Compilation Models
Posted by meilleurs casinos en ligne on 4/14/2010 7:13 AM
Gravatar The first step in ASP.NET ‘compilation’ really comes down to page parsing where the ASP.NET compiler takes your ASPX page (or user control or master page) and parses it into code that can be compiled and then executed. At a very high level ASP.NET turns the ASPX page with its HTML markup, control definitions and script content into a class that can be executed. This process varies depending on the mechanism used to set up your Web pages, using either Inline ASPX page code or the CodeBeside model......
# re: Asp.net 2.0 Compilation Models
Posted by Network virtualisation on 5/7/2010 3:45 AM
Gravatar Nicely presented information in this post, I prefer to read this kind of stuff. The quality of content is fine and the conclusion is good. Thanks for the post.
Post Comment
Title *
Name *
Email
Url
Comment *
Please add 6 and 4 and type the answer here:

About Me

An engineer by training and a software developer at heart. My techniques and approaches meld engineering approaches with software technology.

Core to these principles is a systematic approach to the development of software with a strong lifecycle and process management emphasis through adoption of mature technologies.

Ten years designing heavy structural steel and concrete structures and 12 years in the software development profession have embedded strong project management and business knowledge in my approaches.

Subscribe to Rss Feed


Follow me on twitter @dyardy