TypeScript not Rebuilding JavaScript File

Microsoft

UPDATE: While the solution I presented is fine for builds, what you really want is for the JavaScript file to be regenerated when you save the TypeScript file. The current TypeScript plug-in doesn't do this. Lucky for us, Mads Kristensen has updated the Web Essentials 2012 plug-in to support TypeScript. It will rebuild your .ts files when you save them.

This one is an easy fix. Here's the situation:

You downloaded and installed the TypeScript and opened up your existing ASP.NET MVC 4 application in Visual Studio 2012. After creating a new .ts file, writing some code, and rebuilding the project, you notice that the underlying .js file didn't change. It still has the sample code in it. What do you do??

Unload your project and edit the project file.

We need to add this:

[code language="xml"]

<Target Name="BeforeBuild"> <Exec Command="&quot;$(PROGRAMFILES)Microsoft SDKsTypeScript\0.8.0.0tsc&quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" /> </Target>

[/code]



Why?

The TypeScript team only shipped an MVC3 template. This xml snippet was taken from the MVC 3 project file and dropped in an existing MVC 4 application. Now, when the project is rebuilt, the JavaScript file updates.