Command-Lines
To make it easier to enter commands at the prompt, this page lists all commands as a single line that can be copied and pasted.
Note: Page numbers will be updated once the final print files are made available to me in November 2025.
- Chapter 1 - Hello, C#! Welcome, .NET!
- Chapter 2 - Speaking C#
- Chapter 4 - Writing, Debugging, and Testing Functions
- Chapter 7 - Packaging and Distributing .NET Types
- Page 359 - Checking your .NET SDKs for updates
- Page 372 - Creating a .NET Standard 2.0 class library
- Page 373 - Controlling the .NET SDK
- Page 378 - Understanding dotnet commands
- Page 379 - Getting information about .NET and its environment
- Page 381 - Setting project properties at the command line
- Page 382 - Publishing a self-contained app
- Page 384 - Publishing a single-file app
- Page 385 - Reducing the size of apps using app trimming
- Page 386 - Controlling where build artifacts are created
- Page 390 - Publishing a native AOT project
- Chapter 10 - Working with Data Using Entity Framework Core
- Chapter 11 - Querying and Manipulating Data Using LINQ
- Chapter 12 - Introducing Modern Web Development Using .NET
- Chapter 13 - Building Websites Using ASP.NET Core
- Chapter 14 - Interactive Web Components Using Blazor
- Chapter 15 - Building and Consuming Web Services
code --install-extension ms-dotnettools.csdevkitListing all installed .NET SDKS:
dotnet --list-sdksListing all installed .NET runtimes:
dotnet --list-runtimesDetails of all .NET installations:
dotnet --infoIf you are using the dotnet CLI at the command prompt, add a switch to generate a console app project using the legacy Program class with a Main method:
dotnet new console --use-program-maingit clone https://github.com/markjprice/cs14net10.gitConverting a file-based app to a project-based app:
dotnet project convert app.csPublishing a file-based app:
dotnet publish app.csOutput the current version of the .NET SDK:
dotnet --versionExample of a command line with multiple arguments:
dotnet new console -lang "F#" --name "ExploringConsole"With the dotnet command-line tool, you can pass the name of a new project template, as shown in the following commands:
dotnet new console
dotnet new mvc
Passing four arguments when running your project:
dotnet run firstarg second-arg third:arg "fourth arg"Setting options using arguments:
dotnet run red yellow 50Creating a class library project and adding it to the solution file:
dotnet new classlib -o CalculatorLibdotnet sln add CalculatorLibCreating an XUnit text project and adding it to the solution file:
dotnet new xunit -o CalculatorLibUnitTestsdotnet sln add CalculatorLibUnitTestsRunning a unit test project:
dotnet testListing the installed .NET SDKs with a column to indicate if it has a newer version that can be upgraded to:
dotnet sdk checkCreating a new class library project that targets .NET Standard 2.0:
dotnet new classlib -f netstandard2.0Listing the installed .NET SDKs:
dotnet --list-sdksCreating a global.json file to control to default .NET SDK for projects created in the current folder and its descendents:
dotnet new globaljson --sdk-version 8.0.410Creating a class library project:
dotnet new classlibListing available project templates using .NET 7 or later:
dotnet new listListing available project templates using .NET 6 or earlier:
dotnet new --listListing available project templates using .NET 6 or earlier (short form):
dotnet new -lTo see what .NET SDKs and runtimes are currently installed, alongside information about the OS:
dotnet --infodotnet <command> -p:<PropertyName>=<Value>dotnet build -p:TargetFramework=net6.0dotnet publish -p:PublishDir=./custom_output/dotnet run -p:DefineConstants=DEBUGdotnet build -p:BuildInParallel=falsedotnet build -p:Configuration=Release -p:Version=1.0.0Build and publish the release version for Windows:
dotnet publish -c Release -r win-x64 --self-containedBuild and publish the release version for Windows on ARM64:
dotnet publish -c Release -r win-arm64 --self-containedBuild and publish the release version for macOS on Apple Silicon:
dotnet publish -c Release -r osx-arm64 --self-containedBuild and publish the release version for Linux on Intel:
dotnet publish -c Release -r linux-x64 --self-containeddotnet publish -c Release -r win-x64 --no-self-contained -p:PublishSingleFile=truedotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=truedotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=true -p:PublishTrimmed=Truedotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=true -p:PublishTrimmed=True -p:TrimMode=LinkTo create a MSBuild Directory.Build.props file:
dotnet new buildprops --use-artifactsdotnet publishTo confirm that the path to SQLite has been configured correctly, at any command prompt or terminal, enter the following command to start SQLite:
sqlite3On Linux, you can get set up with SQLite using the following command:
sudo apt-get install sqlite3Creating the Northwind SQLite database:
sqlite3 Northwind.db -init Northwind4SQLite.sqlListing installed dotnet global tools:
dotnet tool list --globalUpdating an older dotnet-ef tool:
dotnet tool update --global dotnet-efInstalling the latest dotnet-ef as a global tool:
dotnet tool install --global dotnet-efUpdating to a specific version of dotnet-ef tool like the latest EF Core 11 preview after February 2026:
dotnet tool update --global dotnet-ef --version 11.0-*Uninstalling an older dotnet-ef tool:
dotnet tool uninstall --global dotnet-efdotnet ef dbcontext scaffold "Data Source=Northwind.db" Microsoft.EntityFrameworkCore.Sqlite --table Categories --table Products --output-dir AutoGenModels --namespace WorkingWithEFCore.AutoGen --data-annotations --context NorthwindDbNote the following:
- The command action:
dbcontext scaffold - The connection string:
"Data Source=Northwind.db" - The database provider:
Microsoft.EntityFrameworkCore.Sqlite - The tables to generate models for:
--table Categories --table Products - The output folder:
--output-dir AutoGenModels - The namespace:
--namespace WorkingWithEFCore.AutoGen - To use data annotations as well as the Fluent API:
--data-annotations - To rename the context from [database_name]Context:
--context NorthwindDb
Creating the Northwind SQLite database:
sqlite3 Northwind.db -init Northwind4Sqlite.sqlTo update a project after changing package versions:
dotnet restoreTo create a new file named Directory.Packages.props:
dotnet new packagespropsCreating the Northwind SQLite database:
sqlite3 Northwind.db -init Northwind4SQLite.sqlChanging to the project folder:
cd Northwind.EntityModels.SqliteCreating the EF Core model for the Northwind database:
dotnet ef dbcontext scaffold "Data Source=../Northwind.db" Microsoft.EntityFrameworkCore.Sqlite --namespace Northwind.EntityModels --data-annotationsTo create a new empty ASP.NET Core project:
dotnet new webStarting an ASP.NET Core project and specifying the https profile:
dotnet run --launch-profile httpsCreating a new project using the Blazor Web App template with server-side or client-side interactivity enabled:
dotnet new blazor --interactivity Auto -o Northwind.BlazorCreating a Web API project using ASP.NET Core Minimal API:
dotnet new webapi -o Northwind.WebApiCreating a Web API project using Minimal API (explicitly):
dotnet new webapi --use-minimal-api -o Northwind.WebApiCreating a Web API project using Minimal APIs (explicitly, short form):
dotnet new webapi -minimal -o Northwind.WebApiCreating a Web API project using controllers:
dotnet new webapi --use-controllers -o Northwind.WebApiCreating a Web API project using controllers (short form):
dotnet new webapi -controllers -o Northwind.WebApi