1

I'm working on TypeScript files with Visual Studio 2012 Express for Web. Since the Web Essentials addon doesn't work with Express editions, and rebuilding the entire project every time I update a script is starting to take too long, I was hoping to convert the following build event (from the TypeScript project template) into an 'External Tools' command that I can place on my toolbar.

<Target Name="BeforeBuild">
  <Message Text="Compiling TypeScript files" />
  <Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
  <Exec Command="tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

Unfortunately... this has kinda lost me. I can't find any documentation on $(TypeScriptSourceMap), nor the @() and %() macros. It doesn't seem to appreciate me copying the command directly either. (Even after converting the HTML entities.)

What could I enter into the External Tools dialog in order to mimic this build event?

I'll try to write a PS script or some such as a workaround, but this would lack the functionality of only working on files with the 'TypeScriptCompile' build action.

YotaXP
  • 3,844
  • 1
  • 22
  • 24

1 Answers1

2

$(TypeScriptSourceMap) comes from about 4 lines earlier in the project file. It's simply " --sourcemap" when in the debug configuration and "" otherwise.

The @() syntax here basically means "For every project item whose build action is TypeScriptCompile, put its full path in double-quotes and join those resulting items by a space.

An emerging best practice for TypeScript projects is to have a "project.ts" file that looks like this:

project.ts

/// <reference path="file1.ts" />
/// <reference path="file2.ts" />
/// ... and so on

file1.ts

/// <reference path="project.ts" />

class alpha { ... }

file2.ts

/// <reference path="project.ts" />

class beta { ... }

With that setup, you can simply run tsc project.ts or tsc project.ts --out app.ts and the right thing will happen.

Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235
  • Interesting. Do you know off hand where that `@()` syntax is documented? TSC is complaining about not finding the file named "(TypeScriptCompile", so it looks like that doesn't get parsed when executing external tools. I may switch to using that project.ts trick anyway, but this stuff is certainly good to know. – YotaXP Dec 13 '12 at 02:23
  • Getting a very odd error with this trick you suggested: `Unknown extension for file: "scripts\project.ts". Only .ts and .d.ts extensions are allowed.` Same goes for when I provide the full path. – YotaXP Dec 13 '12 at 02:38
  • The insane "wrong extension" error has been fixed in 0.8.1.1; I'd recommend upgrading. – Ryan Cavanaugh Dec 13 '12 at 03:35
  • Hah, yeah. Just realized it ment to say the file was missing. I was missing a directory in the path. Thanks again. – YotaXP Dec 13 '12 at 03:49