ASP.NET Core and TypeScript

1. INSTALLATION

1.1. Install ASP.NET Core and TypeScript

First we need to install ASP.NET Core and Visual Studio 2015 . If your version of Visual Studio has not been installed TypeScript, you can install it manually (this is the following tutorial).

1.2. Create demo application

On the menu bar of Visual Studio, follow these steps:

  • Step 1: Select File
  • Step 2: Select New Project (Ctrl + Shift + N)
  • Step 3: Select Visual C #
  • Step 4: Select ASP.NET Web Application

Screen Shot 2016-08-09 at 4.36.25 PM

  • Step 5: Select ASP.NET 5 Empty

Please uncheck "Host in the cloud" when we only run on local (our computer)

Screen Shot 2016-08-09 at 4.36.51 PM

Then click "OK" and test it, make sure it runs well :))

1.3. Server settings

In project.json file we add another "dependencies":

The result will look like this

Replace the contents of Configure in the Startup.cs file to:

2. MORE TYPESCRIPT

The next step is to add a folder for TypeScript.

4e5e795232a47e56fc28f7f9a442c64d917c92d9

We still call it scripts

Screen Shot 2016-08-09 at 4.38.16 PM

2.1. Add TypeScript code

Right-click the scripts folder and click New Item . Then select the typescript file (it can be in the core .Net) and fill in the Name text box is app.ts. Finally click Add .

Screen Shot 2016-08-09 at 4.38.34 PM

2.2. Example code

Type the following code into app.ts.

2.3. Install to build

2.3.1. Configure TypeScript's compiler

Right-click the scripts folder and click New Item . Then select the TypeScript Configuration File and use the default name tsconfig.json .

64336974f588e6dc90ae8005c0d5e2cd9454e0c0

Replace the contents of the file tsconfig.json as follows:

2.3.2. Install NPM

Now we need to install NPM to be able to download the JavaScripts library package. Right-click the project and click New Item . Then select NPM Configuration File and use the default package.json name . Inside devDependencies add gulp and del .

2.3.3. Install gulp

Finally, add a new JavaScript file named gulpfile.js with the content:

The first line tells Visual Studio to run the default task after the build is complete. It will also run task clean when you ask Visual Studio to delete the build.

Now right-click on gulpfile.js and click Task Runner Explorer .

69bbf042882440625678105247aedbc684a99d08

2.4. Write an HTML page

Add a New Item named index.html in the wwwroot directory .

2.5. Test

Now test the project, see how the results are :)))

0981998474bc6679021fd8da2530d6c59402b0a6

So, together we built an ASP.NET Core application with small TypeScript. See you guys in the next series ?

ITZone via viblo

Share the news now