標籤:ogr mon package 今天 after 主程 tno asp alt
前言
前幾天.NET Core發布了.NET Core 1.0.1 R2 預覽版,之前想著有時間嘗試下.NET Core。由於各種原因,就沒有初試。剛好,前幾天看到.NET Core發布新版本了,決定要去一探究竟。於是乎,就立馬去官網尋找相關的資訊,為初探做準備。
下面就開始今天的內容,有兩個部分:安裝和建立樣本程式。
安裝
本人使用的是Windows 10 64位系統,安裝過Visual Studio 2015,如果沒有安裝,請先安裝。
下載安裝檔案
進入.NET Core官網,進入下載頁面1,進入下載頁面2,下載所需的安裝檔案。 需要下載的檔案:
- .NET Core Installer(RC2)
- .NET Core SDK Installer(Preview 1)
- Windows (Server Hosting)
- DotNetCore.1.0.0.RC2-VS2015Tools
- NuGet Manager extension for Visual Studio
LTSLong Term Support (LTS) releases are supported for three years, so they are recommended if you want to stay in the same version for a long period of time. LTS version now is .NET Core 1.0.3CurrentCurrent releases include the latest features and are supported for three months after the next release, so you should always stay in the latest version. Current version now is .NET Core 1.1SDKThe SDK includes the runtime and command line tools for creating .NET Core applicationsRuntimeThe runtime does not include the tools and can only be used to run .NET Core applications.
| |
.NET Core 1.0.3 SDK - Installer |
.NET Core 1.0.3 SDK - Binaries Only |
| Windows |
x64 / x86 .exe |
x64 / x86 .zip |
| macOS |
x64 .pkg |
x64 .tar.gz |
| Linux |
Installing .NET Core on Linux |
| Docker |
Installing .NET Core on Docker |
| Visual Studio 2015 Tools (Preview 2) |
x64 / x86 .exe |
| Visual Studio 2017 Tools (Preview 3) |
Installing .NET Core tools in Visual Studio 2017 Installing .NET Core RC3 tools for all other platforms |
| |
.NET Core 1.0.3 runtime - Installer |
.NET Core 1.0.3 runtime - Binaries Only |
| Windows |
x64 / x86 .exe |
x64 / x86 .zip |
| Windows Server Hosting |
x64 / x86 .exe |
- |
| macOS |
x64 .pkg |
x64 .tar.gz |
| Linux |
Installing .NET Core on Linux |
| Docker |
Installing .NET Core on Docker |
| |
.NET Core 1.1 SDK - Installer |
.NET Core 1.1 SDK - Binaries Only |
| Windows |
x64 / x86 .exe |
x64 / x86 .zip |
| macOS |
x64 .pkg |
x64 .tar.gz |
| Linux |
Installing .NET Core 1.1 on Linux |
| Docker |
Installing .NET Core 1.1 on Docker |
| Visual Studio 2015 Tools (Preview 2) * |
x64 / x86 .exe |
| Visual Studio 2017 Tools (Preview 3) * |
Installing .NET Core tools in Visual Studio 2017 Installing .NET Core RC3 tools for all other platforms |
(*) Visual Studio tools include .NET Core 1.0.1. To add .NET Core 1.1 support you need to also install the .NET Core 1.1 runtime.
| |
.NET Core 1.1 runtime - Installer |
.NET Core 1.1 runtime - Binaries Only |
| Windows |
x64 / x86 .exe |
x64 / x86 .zip |
| Windows Server Hosting |
x64 / x86 .exe |
- |
| macOS |
x64 .pkg |
x64 .tar.gz |
| Linux |
Installing .NET Core 1.1 on Linux |
| Docker |
Installing .NET Core 1.1 on Docker |
Step-by-step instructions Windows macOS Linux
Windows系統直接下載安裝檔案即可。 Windows (Server Hosting)的作用相當於iis,是.NET Core Web項目的服務宿主程式,即可以直接使用Server Hosting運行Web項目。
安裝.NET Core
提示:請先卸載.NET Core之前的版本,否則會報錯。
報錯資訊: The project is configured to use .NET Core SDK version 1.0.0-preview1-002702 which is not installed or cannot be found under the path C:\Program Files\dotnet\bin. These components are required to build and run this project. NetCoreR2.Sample.ConsoleApp
雙擊下載的DotNetCore.1.0.0.RC2-Runtime-x64.exe,選擇同意協議,然後點擊"Insteall"安裝,等待安裝結束。
安裝.NET Core SDK
雙擊下載的DotNetCore.1.0.0.RC2-SDK.Preview1-x64.exe,選擇同意協議,然後點擊"Insteall"安裝,等待安裝結束。
安裝Server Hosting
雙擊下載的DotNetCore.1.0.0.RC2-WindowsHosting.exe,選擇同意協議,然後點擊"Insteall"安裝,等待安裝結束。
安裝.NET Core VS2015Tools
雙擊下載的DotNetCore.1.0.0.RC2-VS2015Tools.Preview1.exe,選擇同意協議,然後點擊"Insteall"安裝,等待安裝結束。
安裝NuGet Manager extension for Visual Studio
雙擊下載的NuGet.Tools.vsix,選擇同意協議,然後點擊"Insteall"安裝,等待安裝結束。 NuGet Manager extension for Visual Studio Download
樣本
樣本有控制台程式和ASP.NET Core Web程式。
.NET Core控制台程式
開啟Visual Studio 2015,建立一個項目:檔案-建立-項目
在左側模板選擇.NET Core,右側選擇控制台應用程式(.NET Core)。 輸入名稱NetCoreR2.Sample.ConsoleApp,點擊"確定"按鈕。 OK,.NET Core控制台應用程式建立完成。
開啟Program.cs檔案,寫入代碼,運行。
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace NetCoreR2.Sample.ConsoleApp{ public class Program { public static void Main(string[] args) { Console.WriteLine("Hello .NET Core 1.0.0 R2 Console App!"); Console.ReadLine(); } }}
如果在這裡提示
ASP.NET Core Web項目
在上面的解決方案上建立一個ASP.NET Core Web項目:添加-建立項目
選擇ASP.NET Core Web Application(.NET Core),點擊"確定",建立項目。
選擇Web 應用程式
更改身分識別驗證為:不進行身分識別驗證,然後確定。
建立好項目後,等待Neget包還原,然後按"F5",調試運行。可以選擇IIS或WindowsHosting,在這選用後者。
接下來,自己寫一個控制器,並顯示資訊。
建立一個HelloController控制器,添加一個Index的Action:
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Mvc;// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace NetCoreR2.Sample.WebApp.Controllers{ public class HelloController : Controller { // GET: /<controller>/ public IActionResult Index() { ViewData["Msg"] = "Hello .NET Core 1.0.0 R2 Asp.Net Core MVC App!"; return View(); } }}
建立對應的視圖檔案,寫入代碼:
@{ ViewData["Title"] = "Hello Index Page";}<h3>@ViewData["Msg"].ToString()</h3>
本文就介紹到這裡。 如有疑問請聯絡我。
.NET Core R2安裝及樣本教程