Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild TypeScript Compile Targets

I have a T4 template that generates a handful of .d.ts files that I want to include in my TypeScript build. I want to understand better when the TypeScript compiler actually gets run as part of a build (or from a .ts file save) so that I can be sure to run my T4 generating target prior to the TypeScript build.

Can anyone give me more details of:

  1. When CompileTypeScript target actually runs?
  2. What PreComputeCompileTypeScript target is actually doing?
  3. Is there a suggested way to ensure that an MSBuild target runs prior to the TypeScript build?

(In case it matters, I am using VS2013 Update 3.)

like image 994
bingles Avatar asked Oct 15 '14 13:10

bingles


People also ask

How do I compile TypeScript code?

To compile your TypeScript code, you can open the Integrated Terminal (Ctrl+`) and type tsc helloworld. ts . This will compile and create a new helloworld. js JavaScript file.

What are MSBuild targets?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.

How does Tsconfig work?

The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.


1 Answers

1.When CompileTypeScript target actually runs?

CompileTypeScript is added to the CompileDependsOn list, this list is defined here: "C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Common.CurrentVersion.targets". The default target (normally build), depends on CoreBuild which in turn requires the Compile target to be executed, see target compile (line 2762) and target corebuild (line 703).

So when the target is build, it executes the TypeScript build because build requires BeforeBuild, CoreBuild and AfterBuild to run. The CoreBuild target requires a lot of targets including compile and TypeScipt added itself in the Microsoft.TypeScript.targets file ("C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TypeScript\Microsoft.TypeScript.targets"). See:

<PropertyGroup>
    <CompileDependsOn>
      CompileTypeScript;
      $(CompileDependsOn);
    </CompileDependsOn>
</PropertyGroup>

2.What PreComputeCompileTypeScript target is actually doing?

It tries to find the most common path for the outDir option when used. Also, when there are no TypeScript files, this task is the one which gives the error: No files to compile (or something). When single output (the --out parameter) is specifiek It does different things. It looks likte VS is providing full paths to the compiler and this task is making them relative when possible (I don't know the reason for this though).

3.Is there a suggested way to ensure that an MSBuild target runs prior to the TypeScript build?

When you create your own msbuild task you can modify the compileDependsOn target. You should do this after you imported the Microsoft.TypeScript.targets. You can change it like this:

<PropertyGroup>
    <CompileDependsOn>
      CompileYourTarget;
      $(CompileDependsOn);
    </CompileDependsOn>
</PropertyGroup>

edit: I changes part 2 of the answer

like image 54
Dick van den Brink Avatar answered Nov 05 '22 21:11

Dick van den Brink