AspNetCore.Docs/aspnetcore/tutorials/first-mvc-app/start-mvc.md

94 lines
4.6 KiB
Markdown
Raw Normal View History

2016-10-29 01:35:15 +08:00
---
2016-11-17 08:24:57 +08:00
title: Getting started with ASP.NET Core MVC and Visual Studio | Microsoft Docs
2016-10-29 01:35:15 +08:00
author: rick-anderson
description: Getting started with ASP.NET Core MVC and Visual Studio
keywords: ASP.NET Core, MVC
2016-10-29 01:35:15 +08:00
ms.author: riande
manager: wpickett
ms.date: 03/07/2017
ms.topic: get-started-article
2016-10-29 01:35:15 +08:00
ms.assetid: 1d18b589-e3fd-4dc6-bde6-fb0f41998d78
2016-11-17 08:24:57 +08:00
ms.technology: aspnet
ms.prod: asp.net-core
2016-10-29 01:35:15 +08:00
uid: tutorials/first-mvc-app/start-mvc
---
# Getting started with ASP.NET Core MVC and Visual Studio
2016-12-17 14:54:46 +08:00
By [Rick Anderson](https://twitter.com/RickAndMSFT)
This tutorial will teach you the basics of building an ASP.NET Core MVC web app using [Visual Studio 2017](https://www.visualstudio.com/).
2016-10-29 01:35:15 +08:00
There are 3 versions of this tutorial:
* macOS: [Create an ASP.NET Core MVC app with Visual Studio for Mac](xref:tutorials/first-mvc-app-mac/start-mvc)
* Windows: [Create an ASP.NET Core MVC app with Visual Studio](xref:tutorials/first-mvc-app/start-mvc)
* macOS, Linux, and Windows: [Create an ASP.NET Core MVC app with Visual Studio Code](xref:tutorials/first-mvc-app-xplat/start-mvc)
2016-10-29 01:35:15 +08:00
2017-03-09 05:01:51 +08:00
For the Visual Studio 2015 version of this tutorial, see the [VS 2015 version of ASP.NET Core documentation in PDF format](https://github.com/aspnet/Docs/blob/master/aspnetcore/common/_static/aspnet-core-project-json.pdf).
2016-10-29 01:35:15 +08:00
## Install Visual Studio and .NET Core
Install Visual Studio Community 2017. Select the Community download. Skip this step if you have Visual Studio 2017 installed.
2016-10-29 01:35:15 +08:00
* [Visual Studio 2017 Home page installer](https://www.visualstudio.com/en-us/visual-studio-homepage-vs.aspx)
2016-10-29 01:35:15 +08:00
Run the installer and select the following workloads:
- **ASP.NET and web development** (under **Web & Cloud**)
- **.NET Core cross-platform development** (under **Other Toolsets**)
![**ASP.NET and web development** (under **Web & Cloud**)](start-mvc/_static/web_workload.png)
2016-10-29 01:35:15 +08:00
![**.NET Core cross-cross-platfrom development** (under **Other Toolsets**)](start-mvc/_static/x_plat_wl.png)
2016-10-29 01:35:15 +08:00
## Create a web app
From Visual Studio, select **File > New > Project**.
2016-10-29 01:35:15 +08:00
2016-11-15 10:07:44 +08:00
![File > New > Project](start-mvc/_static/alt_new_project.png)
2016-10-29 01:35:15 +08:00
Complete the **New Project** dialog:
2016-11-15 10:07:44 +08:00
* In the left pane, tap **.NET Core**
2016-10-29 01:35:15 +08:00
* In the center pane, tap **ASP.NET Core Web Application (.NET Core)**
2016-11-10 13:21:17 +08:00
* Name the project "MvcMovie" (It's important to name the project "MvcMovie" so when you copy code, the namespace will match.)
2016-10-29 01:35:15 +08:00
* Tap **OK**
2016-11-15 10:07:44 +08:00
![New project dialog, .Net core in left pane, ASP.NET Core web ](start-mvc/_static/new_project2.png)
2016-10-29 01:35:15 +08:00
Complete the **New ASP.NET Core Web Application (.NET Core) - MvcMovie** dialog:
2016-10-29 01:35:15 +08:00
* In the version selector drop-down box tap **ASP.NET Core 1.1**
2016-10-29 01:35:15 +08:00
* Tap **Web Application**
* Keep the default **No Authentication**
2016-10-29 01:35:15 +08:00
* Tap **OK**.
2016-11-15 10:07:44 +08:00
![New ASP.NET Core web app](start-mvc/_static/p3.png)
2016-10-29 01:35:15 +08:00
Visual Studio used a default template for the MVC project you just created. You have a working app right now by entering a project name and selecting a few options. This is a simple starter project, and it's a good place to start,
2016-10-29 01:35:15 +08:00
2016-12-12 07:53:43 +08:00
Tap **F5** to run the app in debug mode or **Ctrl-F5** in non-debug mode.
<!-- These images are also used by uid: tutorials/first-mvc-app-xplat/start-mvc -->
2016-11-15 10:07:44 +08:00
![running app](start-mvc/_static/1.png)
2016-10-29 01:35:15 +08:00
* Visual Studio starts [IIS Express](http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-express-overview) and runs your app. Notice that the address bar shows `localhost:port#` and not something like `example.com`. That's because `localhost` is the standard hostname for your local computer. When Visual Studio creates a web project, a random port is used for the web server. In the image above, the port number is 5000. When you run the app, you'll see a different port number.
2016-10-29 01:35:15 +08:00
* Launching the app with **Ctrl+F5** (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.
* You can launch the app in debug or non-debug mode from the **Debug** menu item:
2016-11-15 10:07:44 +08:00
![Debug menu](start-mvc/_static/debug_menu.png)
2016-10-29 01:35:15 +08:00
* You can debug the app by tapping the **IIS Express** button
2016-11-15 10:07:44 +08:00
![IIS Express](start-mvc/_static/iis_express.png)
2016-10-29 01:35:15 +08:00
The default template gives you working **Home, About** and **Contact** links. The browser image above doesn't show these links. Depending on the size of your browser, you might need to click the navigation icon to show them.
2016-10-29 01:35:15 +08:00
2016-11-15 10:07:44 +08:00
![navigation icon in upper right](start-mvc/_static/2.png)
2016-10-29 01:35:15 +08:00
If you were running in debug mode, tap **Shift-F5** to stop debugging.
2016-10-29 01:35:15 +08:00
In the next part of this tutorial, we'll learn about MVC and start writing some code.
>[!div class="step-by-step"]
2016-11-10 13:17:21 +08:00
[Next](adding-controller.md)