Enabling TypeScript builds for library projects in Visual Studio.

If you are creating a modular web application where all content files and script files are embedded in library projects, migrating from JavaScript to TypeScript will need some extra work. As I already discussed in a previous post, debugging TypeScript might be a bit tricky, and I already mentioned there that we have our TypeScript in library assemblies.

I did not mention how we enabled TypeScript build support for these assemblies (since it will not work out of the box for this project type). So here is a small instruction manual:

– Unload the project you want to add TypeScript support to.
– Open the project file in the XML editor.
– Add the following at the end of the file (but before the Project end tag):

<Import Project="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov12.0TypeScriptMicrosoft.TypeScript.targets" />

– Save and close the project file, then load the project again.

The build will now work. However it will likely have problems with overwriting the generated .js files. You probably have those file in source control because you want them added as an Embedded Resource to your output assembly. And if they are in source control they will be read-only by default.

To fix this you can add a pre-build event to your project that clears the read-only attribute (and since we also have the .js.map files are Embedded Resources we fix these up too):

attrib -r /s "$(ProjectDir)*.js"
attrib -r /s "$(ProjectDir)*.js.map"

It is probably possible to use the tf command line tool to actually check these files out instead of changing just the read-only stamps, but the above works fine for us.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.