Skip to content

Latest commit

 

History

History
369 lines (280 loc) · 13.6 KB

File metadata and controls

369 lines (280 loc) · 13.6 KB

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.

Chapter 1 - Introducing Apps and Services with .NET

Page 19 - Managing VS Code extensions at the command prompt

code --list-extensions
code --install-extension ms-dotnettools.csdevkit

Page 20 - Using other project templates

Listing all installed project templates:

dotnet new list

Installing a new project template:

dotnet new --install "Vue.Simple.Template"

Page 25 - Defining project properties to reuse version numbers

After making changes, at the terminal or command prompt, run the following command:

dotnet restore

Page 40 - Installing Docker and an SQL Server container image

Pull down the latest container image for SQL Server 2025, as shown in the following command:

docker pull mcr.microsoft.com/mssql/server:2025-latest

Page 42 - Running the SQL Server container image

Run the container image for SQL Server with a strong password and name the container nw-container, as shown in the following command:

docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=s3cret-Ninja' -p 1433:1433 --name nw-container -d mcr.microsoft.com/mssql/server:2025-latest

Ask Docker to list all containers, both running and stopped, as shown in the following command:

docker ps -a

Page 50 - Removing Docker resources

Stop the nw-container container, as shown in the following command:

docker stop nw-container

Remove the nw-container container, as shown in the following command:

docker rm nw-container

Remove the image to release its disk space, as shown in the following command:

docker rmi mcr.microsoft.com/mssql/server:2025-latest

Page 50 - Setting up the EF Core CLI tool

Check if you have already installed dotnet-ef as a global tool, as shown in the following command:

dotnet tool list --global

If an old version is installed, then update the tool, as shown in the following command:

dotnet tool update --global dotnet-ef

If it is not already installed, then install the latest version, as shown in the following command:

dotnet tool install --global dotnet-ef

To update to the latest .NET 11 preview or release candidate version (which will be available from February 2026 to October 2026), use the following command with a version wildcard:

dotnet tool update --global dotnet-ef --version 11.0-*

You can also remove the tool, as shown in the following command:

dotnet tool uninstall --global dotnet-ef

Page 52 - Creating a class library for entity models

Generate entity class models for all tables, as shown in the following command:

dotnet ef dbcontext scaffold "Data Source=tcp:127.0.0.1,1433;Initial Catalog=Northwind;User Id=sa;Password=s3cret-Ninja;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer --namespace Northwind.EntityModels --data-annotations

Common connection strings

Local SQL Server (default instance):

"Data Source=.;Initial Catalog=Northwind;Integrated Security=true;TrustServerCertificate=true;"

Local SQL Server (replace <your_instance_name> with named instance):

"Data Source=.\<your_instance_name>;Initial Catalog=Northwind;Integrated Security=true;TrustServerCertificate=true;"

Azure SQL Database (replace <your_server_name>, <your_user_name>, and <your_password>):

"Data Source=tcp:<your_server_name>.database.windows.net,1433;Initial Catalog=Northwind;User ID=<your_user_name>;Password=<your_password>;Persist Security Info=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;"

Page 58 - Setting the user and password for SQL Server authentication

Set the two environment variables at the command prompt or terminal, as shown in the following commands:

  • On Windows:
setx MY_SQL_USR <your_user_name>
setx MY_SQL_PWD <your_password>
  • On macOS and Linux:
export MY_SQL_USR=<your_user_name>
export MY_SQL_PWD=<your_password>

Page 66 - Getting help for the dotnet tool

Getting help for a dotnet command like build in a web browser:

dotnet help build

Getting help for a dotnet command like build at the command prompt:

dotnet build -?

Chapter 2 - Buildling Mobile Apps Using .NET MAUI

Page 86 - Installing .NET MAUI workloads manually

To see which workloads are currently installed, enter the following command:

dotnet workload list

To install the .NET MAUI workloads for all platforms, enter the following command at the command line or terminal:

dotnet workload install maui

To update all existing workload installations, enter the following command:

dotnet workload update

To add missing workload installations required for a project, in the folder containing the project file, enter the following command:

dotnet workload restore <projectname>

To remove leftover and unneeded workloads, as shown in the following command:

dotnet workload clean

Page 99 - Adding shell navigation and more content pages

You can create this item using the CLI, as shown in the following command:

dotnet new maui-page-xaml --name SettingsPage.xaml

Page 104 - Defining resources to share across an app

You can create this item using the CLI, as shown in the following command:

dotnet new maui-dict-xaml --name Northwind.xaml

Chapter 3 - Building Desktop Apps Using Avalonia

Page 122 - Installing the Avalonia project templates

To install the Avalonia project templates, as shown in the following command:

dotnet new install Avalonia.Templates

Chapter 4 - Building Web Apps Using Blazor

Page 161 - Reviewing the new Blazor project template

Create a new project using the Blazor Web App project template:

dotnet new blazor --interactivity None -o Northwind.Blazor

Page 167 - Reviewing the new Blazor project template

Start the Northwind.Blazor project, using its https profile without debugging:

dotnet run --launch-profile https

Chapter 9 - Building an LLM-Based Chat Service

Page 385 - Understanding the AI Chat Web App project template

To install the AI Chat Web App project template, at the command prompt or terminal, enter the following command:

dotnet new install Microsoft.Extensions.AI.Templates

Page 387 - Building the chat app

Add a user secrets entry for your OpenAI key, as shown in the following command:

dotnet user-secrets set OpenAi:Key <your-OpenAI-key>

Page 408 - Ollama models

To quickly download and run an Ollama model in interactive mode, use the following command:

ollama run <model>

Page 409 - Ollama CLI

To check its version, as shown in the following command:

ollama --version

To pull down a named model like Meta’s Llama3 or Google’s Gemma3, as shown in the following command:

ollama pull gemma3:1b

To list the available local models:

ollama list

To run a named model (which will also download it if not already pulled), as shown in the following command:

ollama run gemma3:1b

Chapter 10 - Building and Securing Web Services Using Minimal APIs

Page 488 - Authenticating service clients using JWT bearer authentication

Create a local JWT, as shown in the following command:

dotnet user-jwts create

Print all the information for the ID that was assigned, as shown in the following command:

dotnet user-jwts print d7e22000 --show-all

Chapter 11 - Caching, Queuing, and Resilient Background Services

Page 528 - Setting up RabbitMQ using Docker

Pull down the latest container image for RabbitMQ on Docker and run it, opening ports 5672 and 15672 to the container, which are used by default by AMQP, as shown in the following command:

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13.7-management

Page 544 - Processing queued message using a worker service

Start the RabbitMQ container, as shown in the following command:

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13.7-management

Chapter 12 - Broadcasting Real-Time Communication Using SignalR

Page 570 - Building a web client using the SignalR JavaScript library

Install the Library Manager CLI tool, as shown in the following command:

dotnet tool install -g Microsoft.Web.LibraryManager.Cli

Add the signalr.js and signalr.min.js libraries to the project from the unpkg source, as shown in the following command:

libman install @microsoft/signalr@latest -p unpkg -d wwwroot/js/signalr --files dist/browser/signalr.js --files dist/browser/signalr.min.js

Chapter 13 - Combining Data Sources Using GraphQL

Page 633 - Creating a console app client using Strawberry Shake

Create a tools manifest file, as shown in the following command:

dotnet new tool-manifest

Install Strawberry Shake tools for the local project, as shown in the following command:

dotnet tool install StrawberryShake.Tools --local

Add a client for your GraphQL service, as shown in the following command:

dotnet graphql init https://localhost:5131/graphql/ -n NorthwindClient

Chapter 14 - Building Efficient Microservices Using gRPC

Page 686 - Improving a gRPC service with native AOT publish

Run Northwind.Grpc.Service.exe and explicitly specify the URL with the port number to use, as shown in the following command:

Northwind.Grpc.Service.exe --urls "https://localhost:5141"