If you want to use more than one TS compiler, you can install version 2.3 and then set up 2.4 as the primary compiler without uninstalling any versions. In the directory
C:\Program Files (x86)\Microsoft SDKs\TypeScript
, you will see two folders for each version (
2.3
and
2.4
). Make copies of both folders and rename them (
_2.3
and
_2.4
) so you can easily switch between them by changing folder names. Visual Studio typically uses the last installed version (e.g. 2.4), but using the 2.3 compiler in the 2.4 folder can work as well. However, switching between drastically different versions like 1.8 and 2.4 may cause problems because older versions might not recognize certain arguments used by Visual Studio.
This is the basic concept of changing TypeScript compilers. You can manually switch between them or create .bat files to automate this process, which you can then set up as post-build scripts for your Visual Studio Project. This way, Visual Studio will automatically "change" TypeScript compiler versions.
Create a file named C:\set-ts-24.bat
:
rmdir /S /Q "C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4"
xcopy /E /Y "C:\Program Files (x86)\Microsoft SDKs\TypeScript\_2.4" "C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4\"
And another file named C:\set-ts-23.bat
:
rmdir /S /Q "C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4"
xcopy /E /Y "C:\Program Files (x86)\Microsoft SDKs\TypeScript\_2.3" "C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4\"
Next, add a post-build command in your Visual Studio Project file. Right-click on the Project File (not the Solution) in Solution Explorer and select Unload Project.
After unloading the project, edit the jsproj file by right-clicking on the project file again and selecting Edit yourporjectname.jsproj.
In the XML file that opens, add a PropertyGroup element at the end of the document before the closing tag. Set the PostBuildEvent to the path of either set-ts-24.bat
or set-ts-23.bat
script.
...
<PropertyGroup>
<PostBuildEvent>"C:\set-ts-24.bat"</PostBuildEvent>
</PropertyGroup>
</Project>
Save the project file, close it, and then right-click on the project and select Reload Project.