5

I have a question about precompiling ASP.NET web application projects from TeamCity. This is sort of a follow-up question to the following thread:

How to deploy after a build with TeamCity?

I'm done implementing CI from unit testing to autodeploy using the above thread and now I'd like to complement the process with precompiling the project. The project is rather large and I want to avoid any unnecessary delays in the response time after a new deploy.

So, is there a way to do this from TeamCity? Like calling MSBuild with some specific arguments?

Community
  • 1
  • 1
Andras
  • 171
  • 3
  • 16

1 Answers1

3

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>
rrrr-o
  • 2,447
  • 2
  • 24
  • 52
Michael Kennedy
  • 3,202
  • 2
  • 25
  • 34