6

Using tsc command it's as easy as running:

tsc --out all.js js/*.ts

How can I configure Visual Studio to do that when I build my project?

Fenton
  • 241,084
  • 71
  • 387
  • 401
Saulo Vallory
  • 959
  • 9
  • 32

3 Answers3

3

I've found a potentially easier solution by just modifying the build properties of the project (.csproj / .vbproj) you are building:

Project Build Typescript Settings

I'm unsure which version of Typescript that this feature was introduced in. But it seems a much simpler method than the svallory's solution

Source: http://rostacik.net/2013/12/18/how-to-setup-post-build-event-in-visual-studio-to-combine-multiple-typescript-files-to-one-javascript-file/

EDIT: Since Visual Studio 2015, it's now very easy to integrate Grunt/Gulp tasks and have them run in your builds. I've personally be really enjoying using Gulp for more granular control over what files I build and/or minify, and I highly recommend it. Using this guide as a starting point should help.

Zachary Dow
  • 1,897
  • 21
  • 36
2

Just got it. Add this line:

<Exec Command="tsc --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

to the BeforeBuild target of your .csproj or .vbproj file, like this:

<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;', ' ')" />
    <Exec Command="tsc --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>
Saulo Vallory
  • 959
  • 9
  • 32
  • You almost certainly don't want to invoke `tsc` twice like you're doing here (for one, source maps won't work, also it'll take twice as long). Just modify the existing Exec element to include the --out parameter. – Ryan Cavanaugh Jan 14 '13 at 17:44
  • I know it'll take twice as long, but I think it's better than have to modify the build so I can test if everything went fine all the way to the minified script. Source maps are only being generated for the individual file compilation (which I use for debugging). Can you explain to me why source maps won't work? – Saulo Vallory Jan 14 '13 at 20:01
  • When I try this I get an error loading the project: The project file could not be loaded. An XML comment cannot contain '--', and '-' cannot be the last character... – Grinn Jan 18 '13 at 18:31
  • 1
    @Grinn It appears to me that you put that line inside an xml comment. (``) Paste your file to a gist, or publish it somewhere else, and link it here so I can help you more. – Saulo Vallory Jan 19 '13 at 01:03
  • @svallory: How silly of me. It *was* in a comment. I was using Notepad++ to edit the .csproj file (no colorization), and didn't notice that the section was commented out. – Grinn Jan 21 '13 at 13:03
1

It seems that the proposed solution is for typescript 0.8.1.1 and not 0.8.2

Xavier Méhaut
  • 144
  • 1
  • 5