diff --git a/docs/command-lines.md b/docs/command-lines.md index 32752bd..359a6e7 100644 --- a/docs/command-lines.md +++ b/docs/command-lines.md @@ -11,9 +11,38 @@ To make it easier to enter commands at the prompt, this page lists all commands - [Page 36 - Getting help for the dotnet tool](#page-36---getting-help-for-the-dotnet-tool) - [Chapter 2 - Speaking C#](#chapter-2---speaking-c) - [Page 51 - How to output the SDK version](#page-51---how-to-output-the-sdk-version) -- [Chapter 3 -](#chapter-3--) +- [Chapter 3 - Controlling Flow, Converting Types, and Handling Exceptions](#chapter-3---controlling-flow-converting-types-and-handling-exceptions) - [Page 176 - Configuring trace listeners](#page-176---configuring-trace-listeners) - [Page 178 - Adding packages to a project in Visual Studio Code](#page-178---adding-packages-to-a-project-in-visual-studio-code) +- [Chapter 7 - Packaging and Distributing .NET Types](#chapter-7---packaging-and-distributing-net-types) + - [Page 315 - Checking your .NET SDKs for updates](#page-315---checking-your-net-sdks-for-updates) + - [Page 324 - Creating a .NET Standard 2.0 class library](#page-324---creating-a-net-standard-20-class-library) + - [Page 325 - Controlling the .NET SDK](#page-325---controlling-the-net-sdk) + - [Page 328 - Creating new projects](#page-328---creating-new-projects) + - [Page 330 - Publishing a self-contained app](#page-330---publishing-a-self-contained-app) + - [Page 332 - Publishing a single-file app](#page-332---publishing-a-single-file-app) + - [Page 333 - Enabling assembly-level trimming](#page-333---enabling-assembly-level-trimming) + - [Page 333 - Enabling type-level and member-level trimming](#page-333---enabling-type-level-and-member-level-trimming) + - [Page 350 - .NET Upgrade Assistant](#page-350---net-upgrade-assistant) +- [Chapter 10 - Working with Data Using Entity Framework Core](#chapter-10---working-with-data-using-entity-framework-core) + - [Page 440 - Creating the Northwind sample database for SQLite](#page-440---creating-the-northwind-sample-database-for-sqlite) + - [Page 452 - Setting up the dotnet-ef too](#page-452---setting-up-the-dotnet-ef-too) + - [Page 453 - Scaffolding models using an existing database](#page-453---scaffolding-models-using-an-existing-database) +- [Chapter 11 - Querying and Manipulating Data Using LINQ](#chapter-11---querying-and-manipulating-data-using-linq) + - [Page 503 - Building an EF Core model](#page-503---building-an-ef-core-model) +- [Chapter 12 - Introducing Web Development Using ASP.NET Core](#chapter-12---introducing-web-development-using-aspnet-core) + - [Page 540 - Creating a class library for entity models using SQLite](#page-540---creating-a-class-library-for-entity-models-using-sqlite) + - [Page 549 - Creating a class library for entity models using SQL Server](#page-549---creating-a-class-library-for-entity-models-using-sql-server) +- [Chapter 13 - Building Websites Using ASP.NET Core Razor Pages](#chapter-13---building-websites-using-aspnet-core-razor-pages) + - [Page 564 - Testing and securing the website](#page-564---testing-and-securing-the-website) + - [Page 585 - Creating a Razor class library](#page-585---creating-a-razor-class-library) +- [Chapter 14 - Building Websites Using the Model-View-Controller Pattern](#chapter-14---building-websites-using-the-model-view-controller-pattern) + - [Page 602 - Creating an ASP.NET Core MVC website](#page-602---creating-an-aspnet-core-mvc-website) + - [Page 604 - Creating the authentication database for SQL Server LocalDB](#page-604---creating-the-authentication-database-for-sql-server-localdb) +- [Chapter 15 - Building and Consuming Web Services](#chapter-15---building-and-consuming-web-services) + - [Page 695 - Building web services using Minimal APIs](#page-695---building-web-services-using-minimal-apis) +- [Chapter 16 - Building User Interfaces Using Blazor](#chapter-16---building-user-interfaces-using-blazor) + - [Page 717 - Reviewing the Blazor WebAssembly project template](#page-717---reviewing-the-blazor-webassembly-project-template) # Chapter 1 - Hello, C#! Welcome, .NET! @@ -93,7 +122,7 @@ dotnet new console -h dotnet --version ``` -# Chapter 3 - +# Chapter 3 - Controlling Flow, Converting Types, and Handling Exceptions ## Page 176 - Configuring trace listeners @@ -109,23 +138,233 @@ dotnet run --configuration Debug ## Page 178 - Adding packages to a project in Visual Studio Code -Adding the `Microsoft.Extensions.Configuration` package: -``` -dotnet add package Microsoft.Extensions.Configuration -``` - Adding the `Microsoft.Extensions.Configuration.Binder` package: ``` dotnet add package Microsoft.Extensions.Configuration.Binder ``` -Adding the `Microsoft.Extensions.Configuration.FileExtensions` package: -``` -dotnet add package Microsoft.Extensions.Configuration.FileExtensions -``` - Adding the `Microsoft.Extensions.Configuration.Json` package: ``` dotnet add package Microsoft.Extensions.Configuration.Json ``` +> Note: You do not need to add the other two packages because they are transitive depedencies and so will be implicitly referenced. + +# Chapter 7 - Packaging and Distributing .NET Types + +## Page 315 - Checking your .NET SDKs for updates + +``` +dotnet sdk check +``` + +## Page 324 - Creating a .NET Standard 2.0 class library + +``` +dotnet new classlib -f netstandard2.0 +``` + +## Page 325 - Controlling the .NET SDK + +Creating 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 6.0.404 +``` + +## Page 328 - Creating new projects + +Listing available project templates using .NET 7: +``` +dotnet new list +``` + +Listing available project templates using .NET 6: +``` +dotnet new --list +``` + +Listing available project templates using .NET 7 short form: +``` +dotnet new -l +``` + +## Page 330 - Publishing a self-contained app + +Build and publish the release version for Windows: +``` +dotnet publish -c Release -r win10-x64 --self-contained +``` +Build and publish the release version for macOS on Intel: +``` +dotnet publish -c Release -r osx-x64 --self-contained +``` + +Build and publish the release version for macOS on Apple Silicon: +``` +dotnet publish -c Release -r osx.11.0-arm64 --self-contained +``` + +Build and publish the release version for Linux on Intel: +``` +dotnet publish -c Release -r linux-x64 --self-contained +``` + +Build and publish the release version for Linus on ARM64: +``` +dotnet publish -c Release -r linux-arm64 --self-contained +``` + +## Page 332 - Publishing a single-file app + +``` +dotnet publish -c Release -r win10-x64 --no-self-contained /p:PublishSingleFile=true +``` + +``` +dotnet publish -c Release -r win10-x64 --self-contained /p:PublishSingleFile=true +``` + +## Page 333 - Enabling assembly-level trimming + +``` +dotnet publish -c Release -r win10-x64 --self-contained /p:PublishSingleFile=true -p:PublishTrimmed=True +``` + +## Page 333 - Enabling type-level and member-level trimming + +``` +dotnet publish -c Release -r win10-x64 --self-contained /p:PublishSingleFile=true -p:PublishTrimmed=True -p:TrimMode=Link +``` + +## Page 350 - .NET Upgrade Assistant + +Installing the .NET Upgrade Assistant: +``` +dotnet tool install -g upgrade-assistant +``` + +# Chapter 10 - Working with Data Using Entity Framework Core + +## Page 440 - Creating the Northwind sample database for SQLite + +Creating the Northwind SQLite database: +``` +sqlite3 Northwind.db -init Northwind4SQLite.sql +``` + +## Page 452 - Setting up the dotnet-ef too + +Listing installed `dotnet` global tools: +``` +dotnet tool list --global +``` + +Uninstalling an older `dotnet-ef` tool: +``` +dotnet tool uninstall --global dotnet-ef +``` + +Installing the latest `dotnet-ef` as a global tool: +``` +dotnet tool install --global dotnet-ef +``` + +## Page 453 - Scaffolding models using an existing database + +``` +dotnet ef dbcontext scaffold "Filename=Northwind.db" Microsoft.EntityFrameworkCore.Sqlite --table Categories --table Products --output-dir AutoGenModels --namespace WorkingWithEFCore.AutoGen --data-annotations --context Northwind +``` + +Note the following: +- The command action: `dbcontext scaffold` +- The connection string: `"Filename=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 Northwind` + +# Chapter 11 - Querying and Manipulating Data Using LINQ + +## Page 503 - Building an EF Core model + +Creating the Northwind SQLite database: +``` +sqlite3 Northwind.db -init Northwind4Sqlite.sql +``` + +# Chapter 12 - Introducing Web Development Using ASP.NET Core + +## Page 540 - Creating a class library for entity models using SQLite + +Creating the Northwind SQLite database: +``` +sqlite3 Northwind.db -init Northwind4SQLite.sql +``` + +Creating the EF Core model for the Northwind database: +``` +dotnet ef dbcontext scaffold "Filename=../Northwind.db" Microsoft.EntityFrameworkCore.Sqlite --namespace Packt.Shared --data-annotations +``` + +## Page 549 - Creating a class library for entity models using SQL Server + +Creating the EF Core model for the Northwind database: +``` +dotnet ef dbcontext scaffold "Data Source=.;Initial Catalog=Northwind;Integrated Security=true;" Microsoft.EntityFrameworkCore.SqlServer --namespace Packt.Shared --data-annotations +``` + +# Chapter 13 - Building Websites Using ASP.NET Core Razor Pages + +## Page 564 - Testing and securing the website + +Starting an ASP.NET Core project and specifying the `https` profile: +``` +dotnet run --launch-profile https +``` + +## Page 585 - Creating a Razor class library + +``` +dotnet new razorclasslib --support-pages-and-views +``` + +# Chapter 14 - Building Websites Using the Model-View-Controller Pattern + +## Page 602 - Creating an ASP.NET Core MVC website + +Showing all the options for an ASP.NET Core MVC project: +``` +dotnet new mvc --help +``` + +## Page 604 - Creating the authentication database for SQL Server LocalDB + +``` +dotnet ef database update +``` + +# Chapter 15 - Building and Consuming Web Services + +## Page 695 - Building web services using Minimal APIs + +Creating a Web API project using Minimal APIs: +``` +dotnet new webapi --use-minimal-apis +``` + +Creating a Web API project using Minimal APIs short form: +``` +dotnet new webapi -minimal +``` + +# Chapter 16 - Building User Interfaces Using Blazor + +## Page 717 - Reviewing the Blazor WebAssembly project template + +Creating a Blazor WASM project that supports Progressive Web App capabilities and is hosted in an ASP.NET Core website project: +``` +dotnet new blazorwasm --pwa --hosted +``` +