How to precompile an ASP.NET web application from TeamCity?

I have a question about precompiling ASP.NET web application projects from TeamCity. This is a kind of next question to the next section:

How to deploy after build using TeamCity?

I finished the CI implementation from unit testing to auto-expansion using the above thread, and now I would like to complement the process with a preliminary compilation of the project. The project is quite large, and I want to avoid unnecessary delays in response time after a new deployment.

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

+5
source share
1 answer

Of course, this can be done using a custom MSBuild script. Here we start pre-compiling our ASP.NET MVC 3 website (and not that it really depends on the version of ASP.NET).

First, it starts the normal build by running MSBuild against the solution file, then it 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>
+3
source

All Articles