Visual Studio 2015 快速起步

Some developers prefer Visual Studio as their Integrated Development Environment (IDE).

有些开发者喜欢用Visual Studio。

This cookbook describes the steps required to set up and use the Angular QuickStart files in Visual Studio 2015 within an ASP.NET 4.x project.

本烹饪宝典介绍了在Visual Studio 2015的ASP.NET 4.x项目中,用Angular实现“快速起步”所需的步骤。

There is no live example for this cookbook because it describes Visual Studio, not the application.

本烹饪宝典中没有在线例子,因为它介绍的是Visual Studio,而不是应用程序。

ASP.NET 4.x Project

ASP.NET 4.x 项目

This cookbook explains how to set up the QuickStart files with an ASP.NET 4.x project in Visual Studio 2015.

本烹饪书解释了如何使用Visual Studio 2015在ASP.NET 4.x项目中设置《快速起步》文件。

If you prefer a File | New Project experience and are using ASP.NET Core, then consider the experimental ASP.NET Core + Angular 2 template for Visual Studio 2015. Note that the resulting code does not map to the docs. Adjust accordingly.

如果你希望使用ASP.NET Core并体验全新项目, 参见预览版ASP.NET Core + Angular 2 template for Visual Studio 2015。 注意,最终代码与本文不对应,请适当调节。

The steps are as follows:


Prerequisite: Node.js

前提条件: Node.js

Install Node.js® and npm if they are not already on your machine.


Verify that you are running node version 4.6.x or greater, and npm 3.x.x or greater by running node -v and npm -v in a terminal/console window. Older versions produce errors.

在终端或者控制台中运行node -vnpm -v请确认你的Node版本为4.6.x或更高,npm的版本为3.x.x或更高。老版本会引起错误。

Prerequisite: Visual Studio 2015 Update 3

前提条件: Visual Studio 2015 Update 3

The minimum requirement for developing Angular 2 applications with Visual Studio is Update 3. Earlier versions do not follow the best practices for developing applications with TypeScript. To view your version of Visual Studio 2015, go to Help | About Visual Studio.

使用Visual Studio开发Angular 2应用程序的最低要求是Update 3。 早期版本没有遵循使用TypeScript开发应用程序的最佳实践。 要查看你的Visual Studio 2015版本号,到Help | About Visual Studio

If you don't have it, install Visual Studio 2015 Update 3. Or use Tools | Extensions and Updates to update to Update 3 directly from Visual Studio 2015.

如果还没有,安装Visual Studio 2015 Update 3。或者使用Tools | Extensions and Updates来直接在Visual Studio 2015中更新到Update 3。

Prerequisite: Configure External Web tools

前提条件: 配置External Web tools

Configure Visual Studio to use the global external web tools instead of the tools that ship with Visual Studio:

配置Visual Studio来使用全局External Web Tools,而非Visual Studio默认的工具:

Visual Studio will now look first for external tools in the current workspace and if not found then look in the global path and if it is not found there, Visual Studio will use its own versions of the tools.

Visual Studio将优先在当前的工作区查找外部工具,如果没有找到,便查找全局路径,如果还没有找到,Visual Studio就使用自带的工具版本。

Prerequisite: Install TypeScript 2 for Visual Studio 2015

前提条件: 安装TypeScript 2 for Visual Studio 2015

While Visual Studio Update 3 ships with TypeScript support out of the box, it currently doesn’t ship with TypeScript 2, which you need to develop Angular 2 applications.

Visual Studio Update 3自带TypeScript支持,但是它的TypeScript版本开发Angular 2应用需要的不是2。

To install TypeScript 2:

要安装TypeScript 2:

You can find out more about TypeScript 2 support in Visual studio here

你可以在这儿查看更多Visual Studio中TypeScript 2的支持。

At this point, Visual Studio is ready. It’s a good idea to close Visual Studio and restart it to make sure everything is clean.

至此,Visual Studio准备好了。重新启动Visual Stuido,这样我们可以有一个崭新的开始。

Step 1: Download the QuickStart files

第一步: 现在“快速起步”文件

Download the QuickStart source from github. If you downloaded as a zip file, extract the files.


Step 2: Create the Visual Studio ASP.NET project

第二步:创建Visual Studio ASP.net项目

Create the ASP.NET 4.x project in the usual way as follows:

按照下列步骤创建ASP.NET 4.x项目:

In this cookbook we'll select the Empty template with no added folders, no authentication and no hosting. Pick the template and options appropriate for your project.


Step 3: Copy the QuickStart files into the ASP.NET project folder

第三步: 拷贝“快速起步”的文件到ASP.NET项目所在的目录

Copy the QuickStart files we downloaded from github into the folder containing the .csproj file. Include the files in the Visual Studio project as follows:

拷贝从github下载的“快速起步”文件到包含.csproj文件的目录中。按照下面的步骤把它们加到Visual Studio中:

Step 4: Restore the required packages

第四步: 恢复需要的包

Restore the packages required for an Angular application as follows:


Step 5: Build and run the app


First, ensure that index.html is set as the start page. Right-click index.html in Solution Explorer and select option Set As Start Page.

首先,确认index.html已被设置为开始页面。 在Solution Explorer中,右键点击index.html,选择选项Set As Start Page

Build and launch the app with debugger by clicking the Run button or press F5.


It's faster to run without the debugger by pressing Ctrl-F5.


The default browser opens and displays the QuickStart sample application.


Try editing any of the project files. Save and refresh the browser to see the changes.


Note on Routing Applications


If this application used the Angular router, a browser refresh could return a 404 - Page Not Found. Look at the address bar. Does it contain a navigation url (a "deep link") ... any path other than / or /index.html?

如果这个应用程序使用了Angular路由器,刷新浏览器时可能会返回一个404 - Page Not Found。 查看一下地址栏,它是否包含一个导航url(“深链接”)...以及任何除了//index.html以外的路径?

You'll have to configure the server to return index.html for these requests. Until you do, remove the navigation path and refresh again.