24

I wonder if there's a way to set specific TypeScript compiler version for project in Visual Studio. So I could configure a project to always use version 1.0, even if new versions would be released.

I know it was not possible before and I wonder if things changes after TypeScript matured to 1.0 version.

I noticed that now Visual Studio creates <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion> property in a project file, but couldn't find any documentation about it.

Community
  • 1
  • 1
Alexander Puchkov
  • 5,913
  • 4
  • 34
  • 48

4 Answers4

24

If you try to compile a project with <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion> using TypeScript version 1.0 you'll get the following error:

Your project file uses a different version of the TypeScript compiler and tools than is currently installed on this machine. No compiler was found at C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.9\tsc.exe. You may be able to fix this problem by changing the element in your project file.

So it's preventing you from compiling with newer version. It does not however put the compiler into some 0.9 compatibility mode.

But if you have TypeScript 0.9 installed, it will compile against that version. So yes, you can force a specific version of the TypeScript compiler using the attribute.

Basically what the <TypeScriptToolsVersion> do is that it changes the path to the compiler:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\<TypeScriptToolsVersion>\tsc.exe
Kristoffer Lindvall
  • 2,674
  • 1
  • 18
  • 27
  • 2
    This secret project file both of you (you + questioner) are speaking of, which one is it? I can not find this entry anywhere. – Martin Andersson Oct 11 '14 at 09:16
  • 4
    @MartinAndersson web.config – Alexander Puchkov Oct 15 '14 at 15:32
  • 2
    @MartinAndersson I was referring to the msbuild target file. It's your *.csproj file if you're working with a C# project in VS. – Kristoffer Lindvall Nov 06 '14 at 22:19
  • I have TS1.6 and 1.4 installed; I tried changing TypeScriptToolsVersion to 1.4 for a project and encountered an error where it was searching in "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe". Solution is here: https://github.com/Microsoft/TypeScript/issues/3493 – mejdev Sep 30 '15 at 15:40
11

I have solved it by adding $(TypeScriptToolsVersion)\ after TypeScript\ in the condition statement.

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\$(TypeScriptToolsVersion)\Microsoft.TypeScript.targets')" />
HaveSpacesuit
  • 3,572
  • 6
  • 40
  • 59
Oğuzhan Soykan
  • 2,522
  • 2
  • 18
  • 33
6

Visual Studio Version -> VS2013

  1. Install Typescript 1.8 -> https://visualstudiogallery.msdn.microsoft.com/9d0e9172-244a-4943-94e5-bd24dffd9536
  2. Open the folder location of your project e.g. Right click on your project > Open Folder in File Explorer
  3. Find and open the project file via text editor e.g. WebApplication1.csproj
  4. Find the "TypeScriptToolsVersion" tag under the "PropertyGroup" element and use 1.8. Like so,
  <PropertyGroup>
  ......
    <IISExpressUseClassicPipelineMode />
    <TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>
  </PropertyGroup>
Kent Aguilar
  • 5,048
  • 1
  • 33
  • 20
3

We can exclude type script file compilation in visual studio using below line in csproj file.

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> 

after <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion> this line.

Prasad Shigwan
  • 520
  • 5
  • 14