‹ Home
September 11, 2017

Arrrrrg MSBuild!!

I mean just look at this from the TypeScript target file Microsoft.TypeScript.targets

<PropertyGroup Label="TypeScriptToolsVersionHandling">  
  <TypeScriptEffectiveToolsVersion Condition="'$(TypeScriptToolsVersion)' == 'Latest'">$(LastKnownTypeScriptVersion)</TypeScriptEffectiveToolsVersion>
  <TypeScriptEffectiveToolsVersion Condition="'$(TypeScriptToolsVersion)' != 'Latest'">$(TypeScriptToolsVersion)</TypeScriptEffectiveToolsVersion>
  <TypeScriptEffectiveToolsVersion Condition="'$(TypeScriptNuGetToolsVersion)'!=''">$(TypeScriptNuGetToolsVersion)</TypeScriptEffectiveToolsVersion>
  <TypeScriptVersionCheckResult Condition="'$(TypeScriptEffectiveToolsVersion)' == ''">NoneSpecified</TypeScriptVersionCheckResult>
  <TypeScriptVersionCheckResult Condition="'$(TypeScriptEffectiveToolsVersion)' != '' AND Exists('$(TypeScriptSdkDir)\$(TypeScriptEffectiveToolsVersion)\tsc.exe')">Good</TypeScriptVersionCheckResult>
  <TypeScriptVersionCheckResult Condition="'$(TypeScriptEffectiveToolsVersion)' != '' AND !Exists('$(TypeScriptSdkDir)\$(TypeScriptEffectiveToolsVersion)\tsc.exe') AND
      '$(TypeScriptEffectiveToolsVersion)' &gt; '$(LastKnownTypeScriptVersion)' ">Downgrade</TypeScriptVersionCheckResult>
  <TypeScriptVersionCheckResult Condition="'$(TypeScriptEffectiveToolsVersion)' != '' AND !Exists('$(TypeScriptSdkDir)\$(TypeScriptEffectiveToolsVersion)\tsc.exe') AND
      '$(TypeScriptEffectiveToolsVersion)' &lt; '$(LastKnownTypeScriptVersion)' ">Upgrade</TypeScriptVersionCheckResult>
  <TypeScriptVersionCheckResult Condition="'$(TypeScriptNuGetToolsVersion)'!=''">Good</TypeScriptVersionCheckResult>
  <TypeScriptEffectiveToolsVersion Condition="$(TypeScriptVersionCheckResult) != 'Good' ">$(LastKnownTypeScriptVersion)</TypeScriptEffectiveToolsVersion>
</PropertyGroup>  

13 lines to map logic onto XML to describe how to pick the TypeScript version. 13 lines that are mostly just copy paste of one another with &lt; for < and &gt; for >, because that just rolls off the tongue better I guess. 13 lines with a bunch of conditional execution of XML fragments. 13 lines to set variables like TypeScriptVersionCheckResult to 'Good' or 'Upgrade' and then do a string comparison over Condition="$(TypeScriptVersionCheckResult) != 'Good'.

I mean, how is that not insane?