1. Start 'Hello world!'
Set up the environment
Download SDK
Download dotnet SDK here. %[dotnet.microsoft.com/]
You can check your SDK info on PowerShell by below command.
dotnet --info
Command output
$ dotnet --info
.NET SDK:
Version: 7.0.300-preview.23122.5
Commit: cc3d10e792
Runtime Environment:
OS Name: Windows
OS Version: 10.0.25357
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.300-preview.23122.5\
Host:
Version: 7.0.3
Architecture: x64
Commit: 0a2bda10e8
.NET SDKs installed:
6.0.202 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.301 [C:\Program Files\dotnet\sdk]
6.0.404 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
7.0.300-preview.23122.5 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Creating sample console app
option | |
-o | Location of generated project |
-f | implicit framework |
$ dotnet new console -o HelloWorld -f net7.0
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring C:\Users\archdsp\Projects\HelloWorld\HelloWorld.csproj:
Determining projects to restore...
Restored C:\Users\archdsp\Projects\HelloWorld\HelloWorld.csproj (in 97 ms).
Restore succeeded.
Project directory
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/17/2023 1:46 PM obj
-a---- 5/17/2023 1:46 PM 249 HelloWorld.csproj
-a---- 5/17/2023 1:46 PM 105 Program.cs
Compile, Build, Executing
with Roslyn compiler
Find compiler and add the path as Environment Variable
dir -Path C:\ -Filter csc.exe -Recurse -ErrorAction SilentlyContinuecsc
Compile
You can compile Program.cs
with Roslyn compiler with command.
csc.exe Program.cs
This will generate Program.exe under project directory
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/17/2023 1:54 PM obj
-a---- 5/17/2023 1:46 PM 249 HelloWorld.csproj
-a---- 5/17/2023 1:54 PM 122 Program.cs
-a---- 5/17/2023 1:55 PM 4096 Program.exe
More option can be found with
csc.exe /help
With dotnet build
dotnet build .\HelloWorld.csproj
This will generate output under bin\ directory.
Directory: C:\Users\archdsp\Projects\HelloWorld\bin\Debug\net7.0
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 5/17/2023 2:04 PM 422 HelloWorld.deps.json
-a---- 5/17/2023 2:03 PM 5120 HelloWorld.dll
-a---- 5/17/2023 2:03 PM 154112 HelloWorld.exe
-a---- 5/17/2023 2:03 PM 10516 HelloWorld.pdb
-a---- 5/17/2023 2:04 PM 147 HelloWorld.runtimeconfig.json
Difference
Command | Target | On linux |
csc.exe | Source code | GCC or Clang |
dotnet.exe build | .proj file | Make or CMake maybe... |
Executing
dotnet run .\Program.cs
dotnet run .\Program.exe
dotnet run .\HelloWorld.csproj
dotnet .\bin\Debug\net7.0\HelloWorld.dll