TypeScript with Visual Studio 2010 (VS2010) on Windows XP
I've been watching TypeScript for a while and would desperately love to use it, but whilst my home machine is Windows 7 with VS2012, my client-supplied work laptop is Windows XP with VS2010 (for reasons related to supporting legacy software).
TypeScript is open-source so there's no reason that I shouldn't be able to integrate it with VS2010 but Microsoft wish to compel their users to move to VS2012 so don't support VS2010 with their installer for it.
The Obvious Hacks Don't Work ...
The first thing I tried was to run the MSI for VS2012 on XP anyway - that didn't work because the MSI required a version of the installer not present on XP - dead end there as I can't upgrade the installer on my client's laptop even if a later version for XP is available.
The next avenue was to unpack the files in the MSI using 7zip ... in there I find the VSIX and the other installable components: the VSIX installed fine into VS2010 but didn't work well when it came to adding in .ts files even if I installed the TypeScript compiler manually. Worse, though: the license explicitly says that we're not permitted to work around technical limitations of the software - and using unlicenced software would not go down well with my client.
... So Let's Do It Cleanly (and Legally).
First install the TypeScript compiler standalone:
- Go to NodeJS and click Install, following the very brief process to install it.
- Open a normal command-prompt in XP and run: npm install -g typescript
A quick test verified that the compiler (tsc) runs up fine on Windows XP.
Now to integrate with VS2010 so that saving a .ts file automatically compiles it to a dependent .js file.
- Ensure the VS2010 SP1 SDK is installed on VS2010.
- Take a look at the Microsoft Single-File-Generator sample & docs.
- Create an Extensibility project to generate a Visual Studio package.
- Add a class which implements
Microsoft.VisualStudio.Shell.Interop.IVsSingleFileGenerator. - Make the DefaultExtension method return .js.
- Make the Generate method call out to tsc.cmd to get the compiled content.
- Add attributes to make the class show as a custom tool.
- Add registry entry to ensure .ts is associated with the custom tool.
That's pretty straightforward and I had it working quickly. Current limitations:
- Performance: it takes 2-3 seconds to save a file.
- Productivity: no intellisense yet - need to research how to add that in.
- Packaging: currently an extension with manual install - must create a VSIX.
- Presentation: the icon for the .ts file type is currently the vanilla file icon.
And I suspect it probably works in VS2008 too - though I no-longer have a copy :)
There's probably a better way, but at least I have something ... will upload the project here when I've sorted out the intellisense and packaging - and maybe the performance as I believe I should be able to get it down to 1 second.