.NET Core快速入門教程 2、我的第一個.NET Core App(Windows篇)

來源:互聯網
上載者:User

標籤:post   uil   ble   div   views   web   應用程式   oct   一鍵   

一、前言
  • 本篇開發環境?
    1、作業系統: Windows 10 X64
    2、SDK: .NET Core 2.0 Preview
二、安裝 .NET Core SDK
  • 1、下載 .NET Core
    :https://www.microsoft.com/net/download/core
    根據自己電腦情況選擇對應版本即可
    .NET CORE 2.0:https://aka.ms/dotnet-sdk-2.0.0-preview2-win-x64

  • 2、安裝
    微軟出品,一鍵安裝,只需一步,看圖:


三、熟悉命令(cmd)
  • 1、查看版本
#使用命令提示字元(cmd)或者Windows PowerShelldotnet --version
  • 2、選擇性參數介紹
參數 介紹(en) 介紹(ken的翻譯)
new Initialize .NET projects. 初始化項目(相當於通過VS模板建立項目)
restore Restore dependencies specified in the .NET project. 還原項目中的依賴(相當於VS建立ASP.NET MVC,添加相關依賴)
run Compiles and immediately executes a .NET project. 啟動項目
build Builds a .NET project. 編譯項目
publish Publishes a .NET project for deployment (including the runtime). 發布項目(包含runtime)
test Runs unit tests using the test runner specified in the project. 啟動單元測試
pack Creates a NuGet package. 建立nuget包
migrate Migrates a project.json based project to a msbuild based project. 遷移基於project.json,以相容msbuild的編譯
clean Clean build output(s). 清除項目中編譯產生的輸出
sln Modify solution (SLN) files. 修改解決方案檔案.sln
add Add reference to the project. 添加引用
remove Remove reference from the project. 移除引用
list List reference in the project. 列出項目中的引用
nuget Provides additional NuGet commands. 通過nuget參數並附加一些參數,可以進行nuget包管理的一些操作
msbuild Runs Microsoft Build Engine (MSBuild). 使用msbuild進行編譯
vstest Runs Microsoft Test Execution Command Line Tool. 啟動命令列測試載入器
-v/—version Display .NET Core SDK version. 查看.NET Core SDK版本
-i/—info Display .NET Core information. 查看.NET Core 詳細資料
-d/—diagnostics Enable diagnostic output. 啟用診斷
-v/—verbosity Set the verbosity level of the command. 設定冗長命令集?
-h/—help Show help. 查看協助
四、HelloWorld項目
  • 1、建立項目
#使用命令提示字元(cmd)或者Windows PowerShell#1、開啟專案檔夾(如果沒有就先建立好)d:cd d:\projects#2、建立項目dotnet new console -o helloworld#dotnet new :建立&初始化項目#console : 模板類型(相當於VS建立項目選擇控制台應用程式)#-o :指定output路徑名,可以理解為專案檔夾名稱,預設項目名稱=專案檔夾名稱,也可以用-n 單獨指定項目名稱#dotnet new console -n helloworld 效果等同於 dotnet new console -o helloworld#執行輸出:The template "Console Application" was created successfully.Processing post-creation actions...Running ‘dotnet restore‘ on helloworld\helloworld.csproj...  Restoring packages for D:\Projects\helloworld\helloworld.csproj...  Installing Microsoft.NETCore.DotNetAppHost 2.0.0-preview2-25407-01.  Installing Microsoft.Packaging.Tools 1.0.0-preview2-25401-01.  Installing Microsoft.NETCore.DotNetHostResolver 2.0.0-preview2-25407-01.  Installing NETStandard.Library 2.0.0-preview2-25401-01.  Installing Microsoft.NETCore.Platforms 2.0.0-preview2-25405-01.  Installing Microsoft.NETCore.DotNetHostPolicy 2.0.0-preview2-25407-01.  Installing Microsoft.NETCore.App 2.0.0-preview2-25407-01.  Generating MSBuild file D:\Projects\helloworld\obj\helloworld.csproj.nuget.g.props.  Generating MSBuild file D:\Projects\helloworld\obj\helloworld.csproj.nuget.g.targets.  Restore completed in 7.04 sec for D:\Projects\helloworld\helloworld.csproj.Restore succeeded.#專案檔就在d:\projects\hellworld中
  • 2、輸出結果分析
#1、顯示根據指定dotnet new console -o helloworld模板建立了項目The template "Console Application" was created successfully.#2、然後又主動調用了dotnet restore命令來還原項目的引用,主動安裝依賴Processing post-creation actions...Running ‘dotnet restore‘ on helloworld\helloworld.csproj...  Restoring packages for D:\Projects\helloworld\helloworld.csproj...
  • 3、運行
cd d:\projects\helloworlddotnet run#運行結果Hello World!# 恭喜你,你的第一個.NET Core應用程式就這麼誕生了#原始碼請查 d:\projects\hellworld\Program.cs 檔案
五、備忘
  • 支援的項目模板
Templates Short Name Language Tags
Console Application console [C#], F#, VB Common/Console
Class library classlib [C#], F#, VB Common/Library
Unit Test Project mstest [C#], F#, VB Test/MSTest
xUnit Test Project xunit [C#], F#, VB Test/xUnit
ASP.NET Core Empty web [C#] Web/Empty
ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC
ASP.NET Core Web App (Razor Pages) razor [C#] Web/MVC/Razor Pages
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
ASP.NET Core Web API webapi [C#] Web/WebAPI
Nuget Config nugetconfig   Config
Web Config webconfig   Config
Solution File sln   Solution
Razor Page page   Web/ASP.NET
MVC ViewImports viewimports   Web/ASP.NET
MVC ViewStart viewstart   Web/ASP.NET

不得不說:C#才是.NET平台的親兒子啊

  • 如何知道命令支援哪些參數?
    答:利用好—help/-h 參數
#樣本:dotnet --helpdotnet new --helpdotnet restore --helpdotnet new console --helpdotnet new mvc --help

 

  • 系列名稱:.NET Core 快速入門教程
  • 上一篇:.NET Core快速入門教程 1、開篇:說說.NET Core的那些事兒
  • 下一篇:.NET Core快速入門教程 3、我的第一個.NET Core App (CentOS篇)
  • 本篇首次發布:2017-07-14
  • 本篇原文連結:https://ken.io/note/dotnet-core-qucikstart-helloworld-windows

.NET Core快速入門教程 2、我的第一個.NET Core App(Windows篇)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.