Angular2 Setup with MVC4 in Visual Studio

AngularJS (commonly referred to as “Angular” or “Angular.js”) is a complete JavaScript-based open-source front-end web application framework mostly maintained by Google and by a community of individuals and corporations to address many of the challenges encountered in developing single-page applications.

Step 1: Install node and npm in your machine by downloading from the below link

After installing check whether it has installed or not by opening command prompt type below commands

$ Node –v

$ Npm – v

If it installed it will show which version it has installed.

Step 2: Create a new MVC4 project with Visual Studio

Download the files from one drive link and add the below files to your project root folder.!Alczce9o13HwaTebas4JMPHSAF8

Step 3: Close your project solution and take the project location path:

In my case this is my project location path “E:MVC-Angular4MVCAngular4MVCAngular4”

In the command prompt switch it to project folder directory

Install Angular 2 and all its dependencies to your project by typing the below command

$ npm install  – then press enter

It will install npm package and typings package to your project path.

In case if you get any proxy related errors during installation add the below command before execution npm install in the command prompt.

$ npm config set proxy http://proxy:8080 then click on enter then npm install command.

Still if you face any proxy related issues for typings add the below file to your project location in the root folder.

.typingsrc file
 "rejectUnauthorized": false

Once it installed successfully it will create two folders in your project location they are “node_modules” and “typings” don’t include those files into your project.

Then open your solution and replace the below file under view->shared->_Layout.cshtml.

<!DOCTYPE html>
 <html lang="en">

<meta charset=”utf-8″ />
<title>@ViewBag.Title – My ASP.NET MVC Application</title>
<link href=”~/favicon.ico” rel=”shortcut icon” type=”image/x-icon” />
<meta name=”viewport” content=”width=device-width” />

<!– 1. Load libraries –>
<!– Polyfill(s) for older browsers –>
<link rel=”stylesheet” href=”/styles.css”>
<script src=”/node_modules/core-js/client/shim.min.js”></script>
<script src=”/node_modules/zone.js/dist/zone.js”></script>
<script src=”/node_modules/reflect-metadata/Reflect.js”></script>
<script src=”/node_modules/systemjs/dist/system.src.js”></script>
<script src=”/systemjs.config.js”></script>

<!– 2. Configure SystemJS –>

System.import(‘app’).catch(function (err)

<div class=”content-wrapper”>
<div class=”float-left”>
<p class=”site-title”>@Html.ActionLink(“your logo here”, “Index”, “Home”)</p>
<div class=”float-right”>
<section id=”login”>
Hello, <span class=”username”>@User.Identity.Name</span>!
<ul id=”menu”>
<li>@Html.ActionLink(“Home”, “Index”, “Home”)</li>
<li>@Html.ActionLink(“About”, “About”, “Home”)</li>
<li>@Html.ActionLink(“Contact”, “Contact”, “Home”)</li>
<div id=”body”>
@RenderSection(“featured”, required: false)
<section class=”content-wrapper main-content clear-fix”>
<div class=”content-wrapper”>
<div class=”float-left”>
<p>&copy; @DateTime.Now.Year – My ASP.NET MVC Application</p>

@RenderSection(“scripts”, required: false)

In this file if you observe we have imported all the library files and configured startup folder called “app”

Then go to view->Home->index.cshtml page and add the tag with angular selector name say “my-app” <my-app>Loading</my-app>.


 ViewBag.Title = "Home Page";
 @section featured {
 <section class="featured">
 <div class="content-wrapper">
 <hgroup class="title">


Step 4: Create a folder called “App” in your project root folder

Then add the below typescript files under app folder: app.component.ts

import { Component } from ‘@angular/core’;


selector: ‘my-app’,

template: `<h2>Hello {{name}}<h2>`,


export class AppComponent  { name = ‘Angular2’; }


import { NgModule }      from ‘@angular/core’;

import { BrowserModule } from ‘@angular/platform-browser’;

import { AppComponent }  from ‘./app.component’;


imports:      [ BrowserModule ],

declarations: [ AppComponent],

bootstrap:    [ AppComponent ]

//   declarations: [ CoursesComponent,AuthorsComponent,AutoGrowDirective ],

//    bootstrap:    [ CoursesComponent,AuthorsComponent ]


export class AppModule { }


import { platformBrowserDynamic } from ‘@angular/platform-browser-dynamic’;

import { AppModule } from ‘./app.module’;


Step 5: Then go to command prompt and add the below command

“Npm start” then press enter it will start the npm

Then click on F5 or execute your project it will show the app like below with “Hello Angular2”.

Note: We can’t debug type script code in Visual Studio and we therefore need to use Opensource VS code.


Many developers prefer Visual Studio as a developer tool and prefer to use Angular 2 for building web applications. By following this blog you can set up and run Angular 2 app in Visual Studio.


  • Venkataramaiah works with Trigent Software as Senior Software Engineer. He has nearly six years of experience in .NET platform and .NET technologies.