- | rssFeed | My book on MSBuild and Team Build | Archives and Categories Saturday, 31 July 2010

MSBuild 4 : Inline Tasks Part 3, tasks in JavaScript

A while back I talked about the new feature available in MSBuild 4 Inline Tasks in.

In the previous examples I have use C# as my language of choice. C# is not your only choice you can also use VB.Net but you can also use JavaScript! When MSBuild creates the class for the inline task it uses CodeDom to do so, and JavaScript is one of its supported languages. Perhaps its actually called JScript. In any case take a look at the project file below which shows this in action.

<Project ToolsVersion="4.0" DefaultTargets="PrintValues" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

      <Files ParameterType="Microsoft.Build.Framework.ITaskItem[]"/>
      <Code Type="Fragment" Language="javascript">
          function printMessageFor(item : Microsoft.Build.Framework.ITaskItem) {
            Log.LogMessage(item.ItemSpec + "fullpath: " + item.GetMetadata("FullPath"));
          for(var i = 0; i<Files.length; i++) {

    <Source Include="one.cs"/>
    <Source Include="two.cs"/>
    <Source Include="three.cs"/>
    <Source Include="four.cs"/>
  <Target Name="PrintValues">
    <Jsex01 Files="@(Source)" />


Here you can see that I created a new inline task called, Jsex01 and its written in Javascript. Then inside of the PrintValues target this task is called. If you execute the PrintValues target the result will be what you see below.


So if you prefer JavaScript to C# or VB.Net then you should try this out!

Sayed Ibrahim Hashimi

inline task | msbuild | MSBuild 4.0 Saturday, 31 July 2010 05:22:28 (GMT Daylight Time, UTC+01:00)  #     |