Monday, 15 May 2017

TypeScript tsconfig.json being ignored in C# project

TL;DR - Make sure your tsconfig.json file has the Build Action set to Content

I have some TypeScript files included in a .NET project. I added the Microsoft.TypeScript.MSBuild NuGet package to the project to enable the TypeScript compiler to transpile the .ts files to JavaScript. All was good until I wanted to set some compiler options using the tsconfig.json file. I created this file but every time I compiled the project it didn’t do anything different.

I almost pulling out my hair in frustration, so I decided to dig in deeper to find out why this was happening.

First, I ran msbuild with detailed logging. That showed up the following line just before the CompileTypeScript target was run:

Target "PreComputeCompileTypeScriptWithTSConfig" skipped, due to false condition; ('@(ConfigFiles)' != '') was evaluated as ('' != '').

A bit more digging led me to packages\Microsoft.TypeScript.MSBuild.2.3.1\tools\net45\Microsoft.TypeScript.targets – This defines that PreComputeCompileTypeScriptWithTSConfig target which is looking for @(ConfigFiles), which in turn is set in target FindConfigFiles. That target calls the FindConfigFiles task that is in TypeScript.Tasks.dll.

Firing up JetBrains dotPeek to reflect on the code for FindConfigTasks shows that it uses the ContentFiles property to look for existing tsconfig.json files, and that property is set to @(Content) in the targets file.

Jumping back to my project, I notice this:

Screenshot of tsconfig.json and Build Action set to None

Ah haa! Let’s set that Build Action to Content and try again..

Yes! Building the project shows tsc.exe being passed the --project parameter pointing to the tsconfig.json file!

Friday, 5 May 2017

Speaking at NDC Sydney 2017

Well this happened!

Congratulations message

Yes, my talk “Life is like a Box of Chocolate(y)” was accepted for NDC Sydney!

I’ll be speaking about using Chocolatey and BoxStarter as a way of scripting out the configuration of your developer workstation. You might think of these as more “IT” tools, but I want to show developers how easy they are to use.

Combined with Windows 10’s Reset, this means you can rebuild your Windows environment in a matter of minutes, allowing you to apply the “cattle, not pets” approach to your own PC.
NDC Sydney banner

Last year I attended NDC as a volunteer crew member and afterwards said that “this is THE developer event in Australia”.

So go have a look at the speakers and sessions. I reckon it’s a pretty compelling line-up, and if you register before Sunday 14th May, you can take advantage of early bird prices.

I hope to see you there!