Thursday, September 8, 2016

The dreaded 'error MSB6006: "tsc.exe" exited with code 1.' message when building

TypeScript is an amazing tool when working with JavaScript in MVC projects. If you haven't checked it out yet you really should. It makes working with JavaScript so much better and easier. Pluralsight has a terrific course on it here.

This blog post isn't about TypeScript and all its greatness. But rather, it is about quickly debugging build errors when building your web project in Visual Studio and you get the dreaded "tsc.exe exited with code 1".

Just like any build error, the built in tools are usually your best bet for debugging the issue. Whether it is a command in your project's pre-build or post-build events; or a tool like TypeScript failing as part of the build. Usually when calling an external tool from Visual Studio, I have always seen the error reported as "error code 1" or something similar. As an example, try to run the gacutil command from a post-build event when you do NOT run Visual Studio as an admin to see a quick example of this.

Anyway, back to the issue at hand. Today, I pulled down the latest code from MASTER and merged into my branch, build the solution and (insert sad horn sound here) I get the following lone build error:

'tsc.exe' exited with code 1.

To get better insight into the build error, I turn to the tools already at my disposal in Visual Studio. This is a build error, so what better tool to use than MSBUILD? First step, let's change the build logging level so that we can see exactly what is going on and what _exact_ command is being run with tsc.exe.

Go into Visual Studio, Tools - Options, Projects and Solutions - Build and Run, then change the MSBuild project build output verbosity to Diagnostic, click Ok.
Build and Run Settings

Rebuild the solution and then we head to the Output window. Use CTRL-F to bring up the Find window in the Build Output window, and enter tsc.exe. Make sure that you limit the search to the current window. Click the find icon.

This will take you to the first instance of the tsc command:
If you scroll down from here you'll see that this is setting up all of your options for the TypeScript command. The key parameters to note are:
  • FullPathsToFiles - this parameter contains all of the TypeScript (*.ts) files that will be used to generate your JavaScript files.


  • ToolsVersion- the version of TypeScript to use. I'm currently using version 1.8. The default location for installing TypeScript is:  C:\Program Files (x86)\Microsoft SDKs\TypeScript, and then the sub-folder will be which ever version(s) of TypeScript you have installed on your development environment. I have two sub-folders: 1.7 and 1.8,


Click on the find icon again, and you will be taken to the actual TypeScript command that Visual Studio is running to generate your JavaScript files. The command that is run for my particular build is:

 C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe  --module AMD --sourcemap --target ES5 --noEmitOnError --locale en-US "[All files that were in my FullPathsToFiles]"

I removed the entire block of files from the command just to shorten things up a bit for illustration. I don't want my entire blogpost to be the 40 or so TypeScript files from my build command.  :)

Now that we know what command Visual Studio is trying to run for us, we can run it ourselves in a command window and identify the specific build error, and fix it. I run the Developer Command Prompt for VS 2015 as an Administrator. Copy and paste the full tsc.exe command from my Visual Studio 2015 Output Window, to the command prompt and run it.

NOTE: I had to add double quotes around the first part of the command: "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe" because of the spaces in the command path. YMMV.

I run the tsc.exe command and my build error becomes crystal clear:  in my latest merge from MASTER a file was deleted from the repo, but was still referenced in my web project:

"Cannot open file 'C:\{My Path}\{ProjectName}.Web\Scripts\typings\moment\moment-node.d.ts'.
error TS6053: File 'C:/{My Path}\{ProjectName}.Web/Scripts/typings/moment/moment-node.d.ts' not found."

I go to the folder path in my web project, and the .TS file is not there.



A quick phone call to my team and the TS file is added back into the MASTER repo, I merge that into my branch and the build compiles.

So, that's how to resolve the very specific tsc.exe build error. But, I hope this also helps you to debug any build error that is not very detailed (SomeTool exited with error code 1) when Visual Studio runs an "external" tool for you as part of the build process.

See ya around.

Tim

PS: Be sure to change your MSBuild logging level back to minimal. :)

Tuesday, May 17, 2016

SSMS 'Connect to Server' dialog is MIA on multiple monitors

I have been experiencing very frustrating behavior with Sql Server Management Studio (version 11.0.602) when working with multiple monitors.  When I open SSMS, the 'connect to server' dialog does not appear on any of my three monitors.  It seems to appear off the screen somewhere and I cannot get to it.  It's been quite a pain lately.

Granted, my development environment is not 'typical'.  I am running a Windows 10 VM in parallels on a MacBookPro with two external Apple monitors and using the monitor on the MBP as well.

For a while I would just disconnect my external monitors in order to get SSMS to show the 'connect to server' dialog, but I wanted to find a better way; and I wanted to share the solution with anyone else that is experiencing this same issue.

Here are the steps:

  1. Launch Sql Server Management Studio
  2. ALT-TAB to get to the SSMS Window
  3. Press the ESC key to cancel the 'connect to server' dialog
  4. Maximize the SSMS window.
  5. Click Connect, then select Database Engine
Now the 'connect to server' dialog will appear on your external monitors.  It doesn't show up on the SSMS window, but at least it shows up on one of my external monitors.  It doesn't consistently appear on the same external monitor, but hey, at least it appears now.

I hope that helps anyone else that has been experiencing this frustrating behavior.