Last week I wrote about making your TypeScript files compile on save by updating your project files. It is an easy update to make, but then what happens when you check into source control? You are probably going to get an error because your build server can not resolve Microsoft.TypeScript.targets
Two ways to make TypeScript compile on your build server
- You can install TypeScript on your build server.
The big problem with this solution is that it means you have to install a specific version of TypeScript on your build server, and thus make all of your project depend on that single version.
- You can check the TypeScript compiler into Source Control.
This may seem like an odd solution, but for right now I feel that it is the best way to go. It allows all of your projects to be independent of each other, and you do not need to install anything new on any of your servers. (This solution has been proposed to the TypeScript team; thanks, josundt!)
How to Add TypeScript to Source Control
This may look like a lot of steps, but do not worry! All of these steps are small, simple, and they will only take you a minute or two. :)
- Create a TypeScript folder in the root of your solution folder.
- Create a SDKs folder inside of the TypeScript folder.
- Create a MSBuild folder inside of the TypeScript folder.
-
Copy the contents of your TypeScript SDKs install (where the TypeScript compiler, tsc.exe, is located) to the TypeScript\SDKs folder that you have created.
-
By default, that will be located at:
C:\Program Files (x86)\Microsoft SDKs\TypeScript
-
By default, that will be located at:
-
Copy the contents of your TypeScript MSBuild folder (where your TypeScript target files are located) to the TypeScript\MSBuild folder that you have created.
-
By default, for Visual Studio 2012, that will be located at:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TypeScript
-
By default, for Visual Studio 2012, that will be located at:
-
Edit TypeScripts\MSBuild\Microsoft.TypeScript.targets to make the TscToolPath point to your local SDKs folder.
-
The original path would be:
<TscToolPath Condition="'$(TscToolPath)' == ''">$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript</TscToolPath> -
The new path should be:
<TscToolPath Condition="'$(TscToolPath)' == ''">..\TypeScript\SDKs</TscToolPath>
-
The original path would be:
- Open your project file for editing.
-
Update your TypeScript project import to follow a relative path to the local folder.
-
The original path would be:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" /> -
The new path should be:
<Import Project="..\TypeScript\MSBuild\Microsoft.TypeScript.targets" />
-
The original path would be:
- You're done! Reload your project and test it out; if that works, check it in.
Enjoy,
Tom