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 Web Development with Controllers
- Chapter 2 Building Websites Using ASP.NET Core MVC
- Chapter 7 Web User Interface Testing Using Playwright
- Chapter 8 Configuring and Containerizing ASP.NET Core Projects
- Chapter 9 Building Web Services Using ASP.NET Core Web API
- Chapter 10 Building Web Services Using ASP.NET Core OData
- Chapter 11 Building Web Services Using FastEndpoints
- Chapter 12 Web Service Integration Testing
- Chapter 13 Web Content Management Using Umbraco
To clone the book's GitHub repository:
git clone https://github.com/markjprice/web-dev-net9.gitTo pull down the latest container image for Azure SQL Edge:
docker pull mcr.microsoft.com/azure-sql-edge:latestTo run the container image for Azure SQL Edge with a strong password and name the container azuresqledge:
docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=s3cret-Ninja' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edgeTo ask Docker to list all containers, both running and stopped:
docker ps -aTo stop the azuresqledge container:
docker stop azuresqledgeTo remove the azuresqledge container:
docker rm azuresqledgeTo remove the azure-sql-edge image to release its disk space:
docker rmi mcr.microsoft.com/azure-sql-edgeTo check if you have already installed dotnet-ef as a global tool:
dotnet tool list --globalTo update the tool:
dotnet tool update --global dotnet-efTo install the latest version:
dotnet tool install --global dotnet-efTo explicitly set a version, for example, to use a preview, add the --version switch:
dotnet tool update --global dotnet-ef --version 10.0-*To remove the tool:
dotnet tool uninstall --global dotnet-efWarning! Make sure that the SQL Edge container is running because you are about to connect to the server and its Northwind database.
In the Northwind.EntityModels project folder (the folder that contains the .csproj project file), generate entity class models for all tables:
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-annotationsTo set the two environment variables at the command prompt or terminal.
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>Use the help switch to see other options for the ASP.NET CoreMVC project template:
dotnet new mvc --helpRun database migrations:
dotnet ef database updateIf you’re running tests via the command line, you can specify the run settings :
dotnet test --settings Playwright.runsettingsWhen running a test project, you can then specify the browser and channel:
dotnet test -- Playwright.BrowserName=chromium Playwright.LaunchOptions.Channel=msedgeTo add a new xUnit Test Project [C#] / xunit project named Northwind.WebUITests to the MatureWeb solution. In the MatureWeb folder, enter the following commands:
dotnet new xunit -o Northwind.WebUITestsdotnet sln add Northwind.WebUITestsNavigate to Northwind.WebUITests\bin\Debug\net9.0 and, at the command prompt or terminal, install browsers for Playwright to automate:
pwsh playwright.ps1 installStart the Playwright Inspector code generator for the MVC website:
pwsh bin/Debug/net9.0/playwright.ps1 codegen https://localhost:5021/Start the Playwright Inspector code generator with emulation options like setting a view port size:
pwsh bin/Debug/net9.0/playwright.ps1 codegen --viewport-size=800,600 https://localhost:5021/Start the Playwright Inspector code generator to emulate a device:
pwsh bin/Debug/net9.0/playwright.ps1 codegen --device="iPhone 13" https://localhost:5021/To remove the special browsers (chromium, firefox, and webkit) of the current Playwright installation:
pwsh bin/Debug/net9.0/playwright.ps1 uninstallTo remove browsers of other Playwright installations as well:
pwsh bin/Debug/net9.0/playwright.ps1 uninstall --allTo list the Docker images:
docker imagesTo download the Docker image for the sample ASP.NET Core project image and run it with external port 8000 mapped to internal port 8080, interactive TTY mode (-it), and remove it when the container stops (--rm):
docker run --rm -it -p 8000:8080 mcr.microsoft.com/dotnet/samples:aspnetappIn the MatureWeb directory:
dotnet new webapi --use-controllers -o Northwind.WebApidotnet sln add Northwind.WebApiTo create a local JWT:
dotnet user-jwts createResult will have an ID that you can use to identify the JWT:
New JWT saved with ID 'f2d14dfa'.
To print all the information for the ID that was assigned:
dotnet user-jwts print f2d14dfa --show-allIn the MatureWeb directory:
dotnet new webapi --use-controllers -o Northwind.ODatadotnet sln add Northwind.ODataIn the MatureWeb directory:
dotnet new web -o Northwind.FastEndpointsdotnet sln add Northwind.FastEndpointsWhenever you make changes to your models that affect the database schema, you should create a new migration:
dotnet ef migrations add <MigrationName>To run any outstanding migrations:
dotnet ef database updateTo revert to a specified migration point:
dotnet ef database update <MigrationName>To revert all migrations so that the database returns to its original state:
dotnet ef database update 0To add a new xUnit project to the MatureWeb solution:
dotnet new xunit -o BusinessLogicUnitTestsdotnet sln add BusinessLogicUnitTestsTo install the dev tunnel CLI...
On Windows:
winget install Microsoft.devtunnelOn macOS using Homebrew:
brew install --cask devtunnelOn Linux using curl:
curl -sL https://aka.ms/DevTunnelCliInstall | bashTo log in with a Microsoft Entra ID, Microsoft, or GitHub account:
devtunnel user loginStart hosting a simple service on port 8080 that just echoes any HTTP requests to it:
devtunnel echo http -p 8080In another command prompt or terminal window, start hosting a dev tunnel for port 8080:
devtunnel host -p 8080To install the Umbraco version 14.2 project templates:
dotnet new install Umbraco.Templates::14.2.0To confirm that the project templates are installed:
dotnet new list umbraco