title: Customizing the specific output files for various Typescript input files
body: <p>I've got a web project using TypeScript that has some reasonably complex requirements for the compiled output files. So for instance, I need all the *.ts files in one directory to compile down to one single .js file, and all the *.ts files in another directory to compile down to a different .js file. (It's more complex than that, but you get the idea.)</p>
  
  <p>I've been able to get this working using the tsc.exe command-line, using input files and what-not, but I'd like to be able to use MSBuild .targets files - among other things, using tsc.exe from the command-line seems to be pretty poorly supported on continuous integration servers, where it can be located who-knows-where, and certainly isn't likely to be in the path.</p>
  
  <p>According to this answer <a href="https://stackoverflow.com/questions/15651172/typescript-compile-to-single-file-on-save">here</a>, it seems like I should be able to do this using custom build targets. So I've created a custom version of Microsoft.TypeScript.targets, and in addition to the default "CompileTypeScript" target, I've created a second one, "PayboardApiV10", so that the relevant part looks like so:</p>
  
  <pre><code>  &lt;Target Name="CompileTypeScript" Condition="'$(BuildingProject)' != 'false'"&gt;
      &lt;Message Text="Compiling TypeScript files normally" Importance="high"/&gt;
      &lt;VsTsc
        ToolPath="$(TscToolPath)"
        ToolExe="$(TscToolExe)"
        Configurations="$(TypeScriptBuildConfigurations)"
        FullPathsToFiles="@(TypeScriptCompile)"
        YieldDuringToolExecution="$(TscYieldDuringToolExecution)"
        OutFile="$(TypeScriptOutFile)"
        OutDir="$(TypeScriptOutDir)"
        &gt;
        &lt;Output TaskParameter="GeneratedJavascript" ItemName="GeneratedJavascript" /&gt;
      &lt;/VsTsc&gt;
    &lt;/Target&gt;
  
    &lt;Target Name="PayboardApiV10" Condition="'$(BuildingProject)' != 'false'"&gt;
      &lt;Message Text="Compiling TypeScript files for Payboard API v1.0" Importance="high"  /&gt;
      &lt;VsTsc
        ToolPath="$(TscToolPath)"
        ToolExe="$(TscToolExe)"
        Configurations="$(TypeScriptBuildConfigurations)"
        FullPathsToFiles="@(TypeScriptCompile)"
        YieldDuringToolExecution="$(TscYieldDuringToolExecution)"
        OutFile="Payboard.js"
        OutDir="$(ProjectDir)api\v1.0\"
        &gt;
        &lt;Output TaskParameter="GeneratedJavascript" ItemName="GeneratedJavascript" /&gt;
      &lt;/VsTsc&gt;
    &lt;/Target&gt;
  </code></pre>
  
  <p>And then I've specified a "CustomTool" in my project configuration for the specific files that I'd like to get picked up by the "PayboardApiV10" build target, like so:</p>
  
  <p><img src="https://i.stack.imgur.com/axL7f.png" alt="Custom build tool spec"></p>
  
  <p>I should note that I have no idea if I'm doing this bit correctly. I can't seem to find any documentation on it, and the only examples I've been able to find are from that <a href="https://stackoverflow.com/questions/15651172/typescript-compile-to-single-file-on-save">previous answer</a>. And more to the point, when I run my builds, <em>all</em> the TS files in my project get caught up in the first build target, including the ones for which I've specified "MSBuild:PayboardApiV10" for the custom tool. The "PayboardApiV10" tool never seems to get run, i.e., I never see the message "Compiling TypeScript files for Payboard API v1.0".</p>
  
  <p>So two questions:</p>
  
  <p>(1) Is there a better way to do what I'm trying to do? </p>
  
  <p>(2) If this is generally the right way to do it, any ideas as to what I'm doing wrong?</p>