- Mastering ASP.NET Web API
- Mithun Pattankar Malendra Hurbuns
- 467字
- 2021-07-02 20:52:31
Creating and running a basic .NET Core application
We will focus on learning a few basic concepts of .NET Core, and how to work through the command line. The following steps are cross platform to learn .NET Core. Refer the documentation link for further details at https://docs.microsoft.com/en-us/dotnet/core/tools/.
First, let's ensure that everything was installed properly. Open the Console/ Shell (as per your OS of choice), enter the following command to view the CLI commands and tool version, product information, and the runtime environment:
> dotnet -info
The .NET Core CLI provides the following commands to work with:
new
Initializes a basic .NET project
restore
Restores dependencies specified in the .NET project (Runs automatically in most cases)
build
Builds a .NET project
publish
Publishes a .NET project for deployment (including the runtime)
run
Compiles and immediately executes a .NET project
test
Runs unit tests using the test runner specified in the project
pack
Creates a NuGet package
There are a few more commands as well, go look for them too.
In the command line, type the following command:
> dotnet new console --name DemoCoreApp

Let's understand what's happening here in the preceding screenshot:
- dotnet new ;creates a .NET Core C# console project in the context of directory. It has two files: program.cs containing the C# code, and its project file, csproj.
- DemoCoreApp.csproj is a usual .NET project file containing all the details about the project in an XML format. However, in .NET Core, the projects are highly trimmed due to the use of netcoreapp2.0 as the target framework.
- From .NET Core 2.0, whenever we create, build, or publish a project, dotnet restore runs automatically.
As seen in the preceding screenshot, the demo project is open in VS Code; view program.cs to see the C# code for outputting the text on the console.
Just as in traditional .NET projects, we build a C# project, the same way, running the dotnet build command, will perform the routine build and generate the bin and obj folders.
Now dotnet run will run the C# console application, and display the result Hello World on the console.
This C# project can be published and used for deployment by running dotnet publish. This will create the publish folder under the bin directory. This publish folder can then be ported to any machine which has .NET Core SDK installed.
We saw a console application built; we can use the same dotnet new command to create libraries, web, and xunittest projects, as follows:
dotnet new [--type]
The --type option specifies the template type of the project to be created, that is, console, web, lib, and xunittest.
Using the .NET CLI command dotnet new web, you can create a web application that uses .NET Core, and that is called ASP.NET Core.
- Python量化投資指南:基礎、數據與實戰
- Linux網絡程序設計:基于龍芯平臺
- 琢石成器:Windows環境下32位匯編語言程序設計
- Java:High-Performance Apps with Java 9
- HTML5與CSS3基礎教程(第8版)
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- JavaScript+jQuery網頁特效設計任務驅動教程
- IoT Projects with Bluetooth Low Energy
- Flink入門與實戰
- C語言程序設計
- 絕密原型檔案:看看專業產品經理的原型是什么樣
- ASP.NET 4權威指南
- Oracle 11g寶典
- Learning ClojureScript