How to debug Typescript in Visual Studio 2015 asp.net 5? How to debug Typescript in Visual Studio 2015 asp.net 5? typescript typescript

How to debug Typescript in Visual Studio 2015 asp.net 5?


Debugging TypeScript with Visual Studio works with the right settings.

  1. First you make sure that you create source maps when compiling TypeScript to JavaScript. So you should have an xxx.js.map file near every xxx.js.

    Getting source maps by running the TypeScript compiler outside of Visual Studio does not cause any difficulty, at the tsc command line add:

    --sourcemap %1.ts

    your gulp script will usually create sourcemaps by default.

  2. Configure your web application in Visual Studio.

    Set Internet Explorer as the start browser. I got it working only with IE and don't think any other browser will work. (edit: Somewhere I read that there is a Webkit debugging bridge, so Chrome debugging should be possible, but I do not remember the source.)

    In the project properties go to the "Web" tab and configure the "Debuggers" section at the bottom: Disable all debuggers! This is counter intutitive and you might see this error message:

    You have attempted to start the debugger, but based on your current debug settings on the Web properties page there is no process to debug.

    This occurs when the "Don't open a page. Wait for a request from another process" option is selected, and ASP.NET debugging is disabled. Please check your settings on the Web properties page and try again. As the error message says, the Start Action at the top of the Web properties should be another option, like "Current page".

    Set breakpoints in your .ts code inside Visual Studio now or later.

    Hit F5

While you can use the Visual Studio Editor to debug and edit .ts files, "Edit and Continue" will not work, there is currently no browser that can reload .js and .js.map files and continue. (Correct me anyone if I am wrong and I will be happy.)


The best way to handle map files I found is to include the source inside the generated .js files themselves. This is obviously a solution for a dev environment only.

my tsconfig.json below:

{    "compilerOptions": {        "noImplicitAny": false,        "noEmitOnError": true,        "removeComments": false,        "target": "es5",        "module": "system",        "moduleResolution": "node",        "outDir": "./wwwroot/scripts",        "experimentalDecorators": true,        "emitDecoratorMetadata": true,        "inlineSourceMap": true,        "inlineSources": true    },    "exclude": [        "node_modules",        "wwwroot"    ]}

The settings you are after are inlineSourceMap and inlineSources.

This also helps with issues caused by moving the generated .js to different paths and not having to worry about where the map files go.


In ASP.NET 5 RC1 you can instruct the TypeScript compiler to generate .map files by adding a file called tsconfig.json to the project root directory. Visual Studio even has a template for this called "TypeScript JSON Configuration File". By default it has the following contents:

{  "compilerOptions": {    "noImplicitAny": false,    "noEmitOnError": true,    "removeComments": false,    "sourceMap": true,    "target": "es5"  },  "exclude": [    "node_modules",    "wwwroot"  ]}

The "sourceMap" setting instructs the TypeScript compiler to generate the map files which are needed for debugging.

In my case I removed the "wwwroot" value from the "exclude" section because my Angular TypeScript source files are located under wwwroot\App.

Detailed explanation of tsconfig.json settings can be found here: https://github.com/Microsoft/typescript/wiki/tsconfig.json