1
- Start of the Visual Studio 2015 Cookbook
1
+ include ../_util-fns
2
+
3
+ <a id =" top" ></a >
4
+ :marked
5
+ Some developers prefer using Visual Studio as their interactive development environment or IDE.
6
+ For those developers, there are some additional steps required to successfully set up and use the
7
+ Angular 2 QuickStart files.
8
+
9
+ In this cookbook we show how to set up the QuickStart files using Visual Studio. The steps
10
+ required depend on the type of Visual Studio project you use.
11
+
12
+ <a id =" toc" ></a >
13
+ :marked
14
+ ## Table of Contents
15
+
16
+ [ASP.NET 4.x Project](#asp-net-4)
17
+
18
+ :marked
19
+ **This cookbook is for Visual Studio, so there is no live plunker example.
20
+
21
+ .l-main-section
22
+ <a id =" asp-net-4" ></a >
23
+ :marked
24
+ ## ASP.NET 4.x Project
25
+
26
+ The steps for setting up the QuickStart files with an ASP.NET 4.x project in
27
+ Visual Studio 2015 are as follows:
28
+
29
+ :marked
30
+ - [Prerequisite](#prereq): Install Node.js
31
+ - [Step 1](#download): Download the QuickStart files
32
+ - [Step 2](#setup-vs): Set up Visual Studio for TypeScript
33
+ - [Step 3](#create-project): Create the Visual Studio ASP.NET project
34
+ - [Step 4](#copy): Copy the QuickStart files into the ASP.NET project folder
35
+ - [Step 5](#restore): Restore required packages
36
+ - [Step 6](#edit-config): Edit the TypeScript configuration file
37
+ - [Step 7](#build-and-run): Build and run the app
38
+
39
+ - [Step 3](#main): Add `main.#{_docsFor}`, identifying the root component to Angular
40
+ - [Step 4](#index): Add `index.html`, the web page that hosts the application
41
+
42
+ - [Make some changes to the app](#make-some-changes)
43
+ - [Wrap up](#wrap-up)
44
+
45
+ .l-main-section
46
+ h2#prereq Prerequisite: Node.js
47
+
48
+ :marked
49
+ Install **[Node.js® and npm](https://nodejs.org/en/download/)**
50
+ if they are not already on your machine.
51
+ .l-sub-section
52
+ :marked
53
+ **Verify that you are running node `v5.x.x` and npm `3.x.x`**
54
+ by running `node -v` and `npm -v` in a terminal/console window.
55
+ Older and newer versions produce errors.
56
+
57
+ .l-main-section
58
+ h2#download Step 1: Download the QuickStart files
59
+
60
+ :marked
61
+ [Download the QuickStart source](https://github.com/angular/quickstart)
62
+ from github. If you download as a zip file, extract the files.
63
+
64
+ .l-main-section
65
+ h2#setup-vs Step 2: Set up Visual Studio for TypeScript
66
+
67
+ :marked
68
+ Ensure you have the latest version of Visual Studio 2015 installed.
69
+ Then open Visual Studio 2015 and download the latest set of TypeScript tools for
70
+ Visual Studio as follows:
71
+
72
+ * Open `Tools` | `Extensions and Updates`.
73
+ * Select `Online` in the tree on the left.
74
+ * Search for `TypeScript` in the search box in the upper right.
75
+ * Select the latest TypeScript version (`TypeScript 1.8.4 for Visual Studio 2015`).
76
+ * Download and install the package.
77
+
78
+ .l-main-section
79
+ h2#create-project Step 3: Create the Visual Studio ASP.NET project
80
+
81
+ :marked
82
+ Create the ASP.NET 4.x project as follows:
83
+
84
+ * In Visual Studio, select `File` | `New` | `Project` from the menu.
85
+ * In the template tree, select `Templates` | `Visual C#` (or `Visual Basic`) | `Web`.
86
+ * Select the `ASP.NET Web Application` template, give the project a name, and click OK.
87
+ * Select the desired ASP.NET 4.5.2 template and click OK.
88
+ We selected the `Empty` template with no added folders, no authentication and no hosting,
89
+ but you can pick the template and options appropriate for your project.
90
+
91
+ .l-main-section
92
+ h2#copy Step 4: Copy the QuickStart files into the ASP.NET project folder
93
+
94
+ :marked
95
+ Copy the QuickStart files downloaded from github to the folder containing the `.csproj` folder.
96
+ Include the files in the project as follows:
97
+
98
+ * Click the `Show All Files` button in Solution Explorer to show all of the files in the project.
99
+ * Right-click on each folder/file to be included in the project and select `Include in Project`.
100
+ Minimally, include the following folder/files:
101
+ * app folder
102
+ <br>You may see a dialog that asks if you want to search for TypeScript Typings, select `No`.
103
+ * styles.css
104
+ * index.html
105
+ * package.json
106
+ * tsconfig.json
107
+ * typings.json
108
+
109
+ .l-main-section
110
+ h2#restore Step 5: Restore the required packages
111
+
112
+ :marked
113
+ Restore the packages required for an Angular application as follows:
114
+
115
+ * Right-click on the packages.json file in Solution Explorer and select `Restore Packages`.
116
+ <br>This uses npm to install all of the packages defined in the package.json file. This may take some time.
117
+ * If desired, open the Output window (`View` | `Output`) to watch the npm commands execute.
118
+ * When the restore is finished, you should see a message that states: `npm command completed with exit code 0`.
119
+ <br>You may also see some warnings which can be ignored.
120
+ * Click the `Refresh` icon in Solution Explorer and you should see the node_modules as a hidden folder in the project. (It is recommended that you do
121
+ *not* including this folder in the project using `Include in Project`.)
122
+
123
+ .alert.is-important
124
+ :marked
125
+ If you see errors here such as `angular/compiler is not in the npm registry`, then your Visual Studio 2015
126
+ may be using an older version of npm. To use the latest installed version of npm:
127
+
128
+ * Use `Tools` | `Options` to open the Options dialog.
129
+ * In the tree on the left, select `Projects and Solutions` | `External Web Tools`.
130
+ * On the right, move the `$(PATH)` entry above the `$(DevEnvDir`) entries. This tells Visual Studio to
131
+ use the external tools (such as npm) found in your path before using its own version of the external tools.
132
+ * Click OK to close the dialog.
133
+
134
+ .l-main-section
135
+ h2#edit-config Step 6: Edit the TypeScript configuration file
136
+
137
+ :marked
138
+ There is one additional option in the TypeScript configuration (`tsconfig.json`) file that is not required when using other editors,
139
+ but is required if using Visual Studio 2015. Add line 13 to the tsconfig.json file as shown here. After making this change
140
+ exit Visual Studio and reopen it to reload the project.
141
+
142
+ + makeJson('cb-visual-studio-2015/ts/tsconfig.json' , null , 'tsconfig.json (scripts)' )
143
+
144
+ .l-main-section
145
+ h2#build-and-run Step 7: Build and run the app
146
+
147
+ :marked
148
+ Click the Run button or press F5 to build and run the application.
149
+
150
+ This launches the default browser and runs the QuickStart sample application.
151
+
152
+ You can then edit any of the project files and *save*. Then refresh the browser to
153
+ see your changes.
154
+
155
+ .alert.is-important
156
+ :marked
157
+ If you see errors on compilation such as `Property ‘map’ does not exist on type ‘Observable<Response>’` or
158
+ `Observable cannot be found`, then exit Visual Studio and follow the instructions here:
159
+ https://github.com/Microsoft/TypeScript/issues/8518
160
+
161
+ This involves replacing your `C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript.typescriptServices.js` file.
162
+ NOTE: This requires admin privileges.
163
+
164
+ .alert.is-important
165
+ :marked
166
+ When you add routing to the application, the refresh only works when there is no routing path in the address bar.
167
+
168
+ :marked
169
+ [Back to top](#top)
0 commit comments