Command | Description |
dotnet restore | Restore the dependencies (a.k.a. NuGet packages) based on the .csproj or .sln file present in the current dictionary. |
dotnet build | Build the application based on the .csproj or .sln file present in the current dictionary. It implicitly runs the restore command first. |
dotnet run | Run the current application based on the .csproj file present in the current dictionary. It implicitly runs the build and restore commands first. |
dotnet watch run | Watch for file changes. When a file has changed, the CLI updates the code from that file using the hot-reload feature. When that is impossible, it rebuilds the application and then reruns it (equivalent to executing the run command again). If it is a web application, the page should refresh automatically. |
dotnet test | Run the tests based on the .csproj or .sln file present in the current directory. It implicitly runs the build and restore commands first. We cover testing in the next chapter. |
dotnet watch test | Watch for file changes. When a file has changed, the CLI reruns the tests (equivalent to executing the test command again). |
dotnet publish | Publish the current application, based on the .csproj or .sln file present in the current directory, to a directory or remote location, such as a hosting provider. It implicitly runs the build and restore commands first. |
dotnet pack | Create a NuGet package based on the .csproj or .sln file present in the current directory. It implicitly runs the build and restore commands first. You don’t need a .nuspec file. |
dotnet clean | Clean the build(s) output of a project or solution based on the .csproj or .sln file present in the current directory. |
Technical requirements
Throughout the book, we will explore and write code. I recommend installing Visual Studio, Visual Studio Code, or both to help with that. I use Visual Studio and Visual Studio Code. Other alternatives are Visual Studio for Mac, Riders, or any other text editor you choose.Unless you install Visual Studio, which comes with the .NET SDK, you may need to install it. The SDK comes with the CLI we explored earlier and the build tools for running and testing your programs. Look at the README.md file in the GitHub repository for more information and links to those resources.The source code of all chapters is available for download on GitHub at the following address: https://adpg.link/net6.
Summary
This chapter looked at design patterns, anti-patterns, and code smells. We also explored a few of them. We then moved on to a recap of a typical web application’s request/response cycle.We continued by exploring .NET essentials, such as SDK versus runtime and app targets versus .NET Standard. We then dug a little more into the .NET CLI, where I laid down a list of essential commands, including dotnet build and dotnet watch run. We also covered how to create new projects. This has set us up to explore the different possibilities we have when building our .NET applications.In the next two chapters, we explore automated testing and architectural principles. These are foundational chapters for building robust, flexible, and maintainable applications.