33

I can't get Compile-on-Save to work with VS2013. I installed VS2013, reinstalled TS 0.9.0.1, and under "Tools", "Options", Typescript/Project/General, I've checked both of the "Compile on save" options. But when I add a new TS file to my project, and then edit it and save it, the changes aren't reflected in the associated .js file.

Am I doing something wrong? Is anybody else having this problem?

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • i think this is a bug. VS2013 doesn't compile typescript files for me. I still edit and save my files in 2012. – daniel Jul 26 '13 at 21:57

9 Answers9

53

This solved the problem for me:

  1. Go to Options under the Tools menu.
  2. Expand options for Text Editor
  3. Expand options for TypeScript
  4. Expand options for Project
  5. Check “Automatically compile TypeScript file which are not part of the project”
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
Daniel
  • 1,537
  • 1
  • 13
  • 16
16

I had the following situation: the project was created using vs2012 and an earlier version of typescript. I upgraded to VS2013 and the latest version of typescript (0.9.1.1) and scripts were not compiled on save.

I then excluded the typescript file from my project and added it again using Add existing file. After that the typescript file compiles fine on save!!

rekna
  • 5,313
  • 7
  • 45
  • 54
  • Yep, it looks like it needs to have one file added that way so that it knows to update the project file with the necessary references. – Dan Friedman Dec 06 '13 at 15:22
  • 2
    I believe this causes it to work as it sets the build action to TypeScriptCompile, just as it does automatically when adding new TypeScript files – Brett Postin Dec 11 '13 at 22:09
  • 1
    For me was exclude and include not enough. What I do was I deleted the .ts file(s) from project and recreated them again from scratch with copy & paste. – Anton Kalcik Apr 02 '14 at 14:55
  • Do check the Properties of the file. Even when re-adding, the file was not properly setting the Build Action to 'TypeScriptCompile'...at least in the case of my file that would no longer compile. – Bob Aug 04 '14 at 13:30
7

TypeScript 0.9.5 compile on save stopped working for me on an existing project after I upgraded to Web Essentials 1.85 (Feb 14). I reinstalled both to no avail but after seeing it work for new projects I tried changing this line in my csproj, from this;

<Project ToolsVersion="4.0" />

to

<Project ToolsVersion="12.0"/>

And magically, compile on save started working again.

cirrus
  • 5,624
  • 8
  • 44
  • 62
4

Try following these instructions:

Compile-on-Save

I've been struggling to get my head around this too but I think I have it sorted. I think part of the confusion comes from the differences in approach between WebEssentials and the new TypeScript plugin integration.

I was an early adopter of TypeScript and used the WebEssentials tooling in 2012 to compile on save. I had this configured to generate .js and .min.js files, which were both added to the project automatically.

When upgrading to VS 2013 I was looking for the same functionality from the in-built TypeScript support, however it does not exist (as far as I can tell).

Instead I believe the integrated tooling in 2013 covers both development and production workflows.

The above instructions set you up for build time compilation which should occur during release. During development the "Compile on Save" feature generates the files on disk, but does not add them to the project.

I then realised the generated files don't actually need to be part of the project as they were before, and why it's better than the WebEssentials solution (excluding the lack of preview window!).

Brett Postin
  • 11,215
  • 10
  • 60
  • 95
  • Editing the csproj file as explained in the link worked for me. More specifically, adding the `PropertyGroup` and `Import` target sections (otherwise I had intellisense issues, and nothing was ever compiled, even with typescript 1.8.5 and visual 2013 update 5). The answer marked as solution (enabling "Automatically compile TypeScript file which are not part of the project") did NOT work for me: each time I reopened the solution, I needed to edit/save each file for intellisense to know about them. – youen Nov 18 '16 at 21:39
2

For me, even if Compile-on-save was working (Visual Studio 2013), if someone else tried to run the web project, it would not automatically generate the javascript files. In my project, I included *.js files and *.js.map files to prevent IIS from not taking the new version when I modify the *.ts files. But these files are not included in the source control.

What I thus did is that I included the following line at the end of the csproj project file:

<Target Name="AfterBuild">
  <Exec Command="tsc.exe --sourcemap _core.ts" WorkingDirectory="$(MSBuildProjectDirectory)\js" />
</Target>

where _core.ts is a file in the js folder which -- I am sure -- references all files directly or indirectly through headers at its beginning.

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

so that tsc.exe processes all the dependent files as well.

Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
1

Beside the steps above, if the compile on save is not working yet, mark your project as the startup project (on VS 2013 solution explorer, right-click, Set as StartUp Project).

This solution was found on Codeplex by nicholasjgreen and is posted on the comments at http://typescript.codeplex.com/wikipage?title=Compile-on-Save.

Eduardo Lucas
  • 44
  • 1
  • 3
1

I solved this problem by adding the function to the end of the Typescript file. It didn't work when the 'new' function was typed at the top of the page (before the other functions) but when I added it below the last function it worked. Only took three hours!

0

Have you added the typescript files using drag'n'drop? Then it could be that the build action of the files has the wrong value. Use the property window of the files (F4 or alt + enter) and verify the build action there...

A. K-R
  • 2,002
  • 1
  • 14
  • 16
  • Thanks for the suggestion. The build action is set to TypeScriptCompile, which I *think* is right. – Ken Smith Jul 18 '13 at 14:53
  • Some of my Scripts have that type, others have CodeAnalysisDictionary - both build types work for me. – A. K-R Jul 18 '13 at 15:31
  • 4
    Sigh. Turns out it was a rookie mistake. I hadn't followed the instructions to get TS compile-on-save to work with my project, as defined here: https://typescript.codeplex.com/wikipage?title=Compile-on-Save – Ken Smith Jul 18 '13 at 16:10
0

This feature is a little easier to find using the following method. (VS2015)

  1. Go to Tools > Options.
  2. Make sure you have "Show all settings" selected. This is a checkbox near the bottom of the window.
  3. Put "typescript" in the search bar and press enter.
  4. Now the list should be filtered. Navigate to the setting: Text editor > Typescript > Project > General.
  5. Now select “Automatically compile TypeScript files which are not part of the project”. Press OK.
prolink007
  • 33,872
  • 24
  • 117
  • 185