Setting up ASP.NET Core in Visual Studio 2017 with npm, webpack, and TypeScript: Part I
Tags: visualstudio2017, aspnetcore, webpack, node
Published: 2017-04-17 08:08:25

---
title: "Setting up ASP.NET Core in Visual Studio 2017 with npm, webpack, and TypeScript: Part I"
published: true
description: The days of page refreshes on web sites are long gone.
tags: Visual Studio 2017, asp.net core, webpack, node.js
canonical_url: http://leruplund.dk/2017/04/15/setting-up-asp-net-core-in-visual-studio-2017-with-npm-webpack-and-typescript-part-i/
series: asp-net-core-with-npm-webpack-typescript
---

<em>This post first appeared on my personal [blog](http://leruplund.dk/2017/04/15/setting-up-asp-net-core-in-visual-studio-2017-with-npm-webpack-and-typescript-part-i/).</em>

### Example code on [Github](https://github.com/t4rzsan/aspnet-core-with-webpack/tree/master).

Things have been moving so fast in the last couple of years when it comes to web development.Â  The days of page refreshes on web sites are long gone.Â  The youngsters and hipsters want ajax, animations, spinners, and what not.Â  The JavaScript world has exploded with cool libraries and what is the newest, coolest, hottest library right now changes faster than I change my underwear (or maybe I'm just getting old, or I need to change my underwear more often).

Recently, Microsoft came out with the final release of Visual Studio 2017 (VS), and I figured now would be a good time to get my head around ASP.NET Core and all the cool JavaScript things.

The case in mind is a small intranet website that will allow the users to do some quick actuarial calculations.

**Getting started**
Let's start by creating a Visual Studio ASP.NET Core project.Â  Start Visual Studio 2017 and create a new project from the "ASP.NET Core Web Application (.NET Framework)" template.Â  We will choose this template to make the code compatible with non-Core assemblies (the actuarial assemblies are compiled for .NET 4.5.2).

At the top of the dialog, choose which .NET framework you wish to be compatible with.

<img class="alignnone size-large wp-image-66" src="http://leruplund.dk/wp-content/uploads/2017/04/Udklip-1024x710.png" alt="" width="1008" height="699" />

In the next dialog choose "Web Application", and Visual Studio will set up a basic structure for your project.Â  Among other things, Visual Studio creates a folder named "wwwroot".Â  This is where the files that will be published to the actual web server should be placed.Â  Don't put anything else such as your code in that folder.

**Setting up npm**
To get all the JavaScript goodness into our project, we need to install the Node Package Manager (npm).  As the name implies, npm is a package manager for JavaScript.  Think Nuget for Javascript kind of thing.  But npm can do more than that.  It can also build TypeScript with the help of webpack which is what we will do later on.

You can install npm (Node.js) through the Visual Studio installer but you should always make sure that you are running the latest version.  You can also download and install from the [node.js web site][1].

Now we need to initialize node for our VS project directory.  Open a command prompt and cd to the VS project folder (the folder where the .csproj file is located).

Run the command:

```npm init -y```

This will initialize npm for your project with default settings.  The initialization creates a file named package.json.  Notice how VS automatically recognizes the file and adds it to the web project.

You might want to open the package.json file and change the name attribute to all lower case since upper case letters are not supported (I have no idea why npm init does not change it to lower case while it is at it).

Run the following command to update npm at a later time.

```npm install npm@latest```

**Installing webpack**
Next up is [webpack][2].  Webpack seems to be the Swiss Army knife of JavaScript and it looks like people are moving from things like Grunt and Gulp to webpack. Also, in my humble opinion, the webpack documentation is far better than what you will se for a lot of the other "hot and cool" open source JavaScript libraries.  

We will be using webpack for compiling TypeScript and for bundling script files. 

Install webpack with npm by running the command

``` npm install webpack --save-dev```

This will save webpack as a development (not production) dependency in package.json. We will be using webpack as part of the build process, hence the development dependency.  The npm install command also creates a folder named "node_modules" in your project folder with dependencies.  Do _not_ include this folder in your project.

**Next**
In the [next part][3] of this series we will get up and running with TypeScript.

[1]: https://nodejs.org/en/download/
[2]: https://webpack.js.org/
[3]: https://dev.to/t4rzsan/setting-up-aspnet-core-in-visual-studio-2017-with-npm-webpack-and-typescript-part-ii
Â