Friday, 28 December 2012

TypeScript and MSBuild example

This article expects you to have basic knowledge aboutMS BUILD and have installed typescript on your machine.

I have started to use TypeScript. Now when the page is compiled I need to compile those TS files into JavaScript.

As default TypeScript does not compile, we need to add out compilation in order for us to get JavaScript files


Definition of my example BuildTypeScript.msbuild



<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildTypeScript" ToolsVersion="4.0" >

  <PropertyGroup>
  <sourcedir>D:\WebPortal</sourcedir>  
  <TypeScriptVersion>0.8.1.1</TypeScriptVersion>
  </PropertyGroup>  

 <ItemGroup> 
  <TypeScriptCompile Include="$(sourcedir)\**\*.ts" />
 </ItemGroup> 

  <Target Name="BuildTypeScript" Inputs="@(TypeScriptCompile)" Outputs="%(Identity).Dummy">
  <Message Text="@(TypeScriptCompile)" />  
<Exec Command="&quot;$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\$(TypeScriptVersion)\tsc&quot; -target ES5 &quot;@(TypeScriptCompile)&quot;" />
  </Target>
</Project>



Check against your version:


  • I have added default value where is source of my project that you might need to update.
  • You need to check what version of type script has been installed on your local pc/build server

Command to execute:

msbuild BuildTypeScript.msbuild


Reference:
http://daysincode.blogspot.com/2012/12/msbuild-target-batching-for-each.html