What happened to option to disable auto-compile?

Topics: General
Jul 1, 2014 at 7:55 PM
In the 0.9.1 plugin for visual studio, we could disable automatic compilation for files both in and out of project. The options looked like the below (from Tools...Options...Text Editor...TypeScript...Project)

Compile On Save
"Automatically compile TypeScript files which are part of a project"
"Automatically compile TypeScript files which are not part of a project"

When I went to the 1.0 plugin, I only get the option below:

Compile On Save
"Automatically compile TypeScript files which are not part of a project"


Since I can no longer turn off automatic compile, VSNET gets much slower and frequently pops up warnings that I am overwriting a file that has been updated since it was last opened. Those files are never open anywhere, but in 0.9.1, turning off auto-compile always fixed this.

I am using a "class library" style pattern where all ts is compiled using the command-line compiler using a pre-build event to an embedded resource. Web Apps then use WebResource.axd urls to the single generated file that is embedded.

I would really like to be able to turn off compile-on-save for files in the project again. The extra little js files serve no purpose and noticeably affect VSNET performance.
Coordinator
Jul 2, 2014 at 5:05 PM
The configuration to disable compile-on-save is in the project properties. If you are using Visual Studio 2013, and your project is a C#/VB/node tools project go to project properties, select "TypeScript Build" tab, you should find a check box under "General" titled "Compile on save". this will disable it for your specific project.

If you have Visual Studio 2012, you will need to manually add it to your project file, before the reference to the standard targets, "Microsoft.TypeScript.targets":
<TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
For loose files (files that the language service does not identify as belonging to a project), you still have the global option in Tools\Options\Text Editor\TypeScript\Project\General\Compile on Save to disable the feature.

Having said that, Compile-on-save should is not blocking; it should not block you from using Visual Studio, as it runs on a background thread. So CoS causing a delay would be a bug that we need to look into. The warning for overwriting files are probably because you have the js file open, and you can disable the warning from Tools\Options\Environment\Documents\Detect when file is changed outside the environment.

One more thing to note, is if you use the default build system, CoS will load your build configuration from the project properties, and build the file correctly as you expect (to a single output if I understood your setup correctly) and you would not get the extra .js file for each .ts file. What you would get in return is a pseudo-incremental build, where only changed files will be processed and output will be up-to-date more often.
Marked as answer by dwlovell on 7/2/2014 at 5:44 PM
Jul 3, 2014 at 12:52 AM
Thank you for that project file tip. That worked and everything seems to be smoother now. I am also no longer getting the warning about overwriting files. I would get it repeatedly when saving .ts files multiple times in short intervals. I have a habit of ALT-F-S to quickly re-save after even the tiniest of edits. Even though I would have no other files open except the current .ts, I would repeatedly get that warning popup. For some reason, turning off compile-on-save resolves this.

I will describe the pattern I use to build Typescript libraries so that it might be useful to others:

Here are the settings I add to my class library project file to get this to work:
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
    <TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
    <TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
  </PropertyGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets')" />
  <PropertyGroup>
    <PreBuildEvent>attrib -R "$(ProjectDir)\Generated\*.js"
tsc.exe "@$(ProjectDir)Grid.tscargs"
attrib +R "$(ProjectDir)\Generated\*.js"</PreBuildEvent>
  </PropertyGroup>
Note the ".tscargs" file. This is my own extension that has all of the command line params to the tsc compiler. Here is an example of the tscargs contents:
--out ..\..\Generated\Grid.js
--target ES3
--removeComments
--noImplicitAny
..\..\Lib\JQuery.d.ts
..\..\Grid\Interface\IColumn.d.ts
..\..\Grid\Interface\IGrid.d.ts
..\..\Grid\Column.ts
..\..\Grid\Grid.ts
So you can see that the pre-build event, unmarks the "generated" file as readonly, regenerates it, then re-marks it readonly. This generated file is marked "embedded resource". So now when this pre-build event touches it, it causes the assembly to be rebuilt, even if there were no other "code" changes. Additionally, other assemblies that "reference" my class lib will get the output copied as well. So I can just change a .ts file, build and run, just like C# code. Consuming application projects can either use a post-build event to copy the generated file into their own scripts folder, or use WebResource.axd to service the content directly from the embedded resource.

Anyways, that's my pattern and with that minor change to turn off CoS, it is working perfectly. I have not tried 2013 yet, and I couldn't find anything built into 2012 to do this type of integrated build.