After a bit of experimenting with TypeScript, I found two ways to automatically compile .ts to .js so far.
The advantage of this approach is that all your TypeScript code is kept in a separate project from your ASP.Net or ASP.Net MVC project.
One solution is to set the project’s output directory to the script directory of your web project, and in Configuration Manager define the build order to build the TypeScript project before the web project.
For this method to work, the .js files generates by the TypeScript project must be included in the web project to be published.
But how does the TypeScript project know how to invoke the tsc compiler for .ts files? Well, it says so in the .csproj file by defining a BeforeBuild target:
<Target Name="BeforeBuild"> <Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\ TypeScript.8.0.0\tsc" @(TypeScriptCompile ->'"%(fullpath)"', ' ')" /> </Target>
If you copy this block to your web project’s .csproj file (unload project, edit project, reload project), it should make your existing project compile .ts files before invoking the regular C# build.
An answer on SO also suggest an extension that compiles on save, but this only works in VS 2012.