Asp.net 2.0 Compilation Models


Compliation of asp.net, c#, vb.net applications can depend on different aspects. Keep in mind the following factors.

- April 20, 2015

Rest of the Story:

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>