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