Sure, it can be done with a custom MSBuild script. Here's the one we run to precompile our ASP.NET MVC 3 website (not that it really varies by ASP.NET version).
First it runs the regular build by running MSBuild against the solution file, then runs this custom MSBuild code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <PropertyGroup>
    <WebProject>Web\ChatPast.Web\ChatPast.Web.csproj</WebProject>
    <WebProjectFolder>Web\ChatPast.Web</WebProjectFolder>
    <WebPublishFolder>ChatPastWebPublish</WebPublishFolder>
  </PropertyGroup>
  <ItemGroup>
    <ZipFiles Include="$(teamcity_build_workingDir)\src\ChatPast\$(WebPublishFolder)\**\*.*" />
  </ItemGroup>
  <Target Name="Build">
      <!-- Compilation of all projects -->
      <MSBuild Projects="ChatPast.sln" Properties="Configuration=Release"/>
      <!-- Creating web publish folder. -->
      <RemoveDir Directories="$(WebPublishFolder)"/>
      <MakeDir Directories="$(WebPublishFolder)"/>
      <!-- Running ASP.NET publish -->
      <MSBuild Projects="$(WebProject)"
           Targets="ResolveReferences;_CopyWebApplication"
           Properties="Configuration=Release;WebProjectOutputDir=..\..\$(WebPublishFolder);OutDir=..\..\$(WebPublishFolder)\bin\" />
  </Target>
</Project>