English
Checkpoint
What must work
Run these commands in the repository root. Each must succeed:
powershell
dotnet buildpowershell
dotnet format Chatex.slnx --verify-no-changespowershell
docker compose up --detach --waitpowershell
dotnet ef --versionpowershell
./Run.ps1Compare your repository with the reference: the files global.json, Directory.Build.props, Directory.Packages.props, compose.yaml, dotnet-tools.json and Run.ps1 must be identical to those in D:\Work\Chatex-Reference, for example:
powershell
git diff --no-index Directory.Build.props D:\Work\Chatex-Reference\Directory.Build.propsNo output means no difference. The .csproj files differ for now: the reference ones already have the package references of later topics.
Common mistakes
Table 2.3. Common mistakes when creating the solution
| Symptom | Cause | Fix |
|---|---|---|
A compatible .NET SDK was not found | no SDK of the 10.0 line from 10.0.403 up is installed | install the .NET 10 SDK; check with dotnet --list-sdks |
error NU1008: Projects that use central package version management should not define the version on the PackageReference items | a PackageReference has a Version attribute | remove the attribute; the version belongs in Directory.Packages.props |
error NU1010: The PackageReference items … do not have corresponding PackageVersion | a package is referenced, but its version is missing from Directory.Packages.props | add a PackageVersion line for it |
error ENDOFLINE from dotnet format --verify-no-changes | files with CR LF line endings | run dotnet format Chatex.slnx |
bin/ or obj/ folders appear in git status | .gitignore is missing or not in the repository root | download it as in step 6 |
port is already allocated when starting the container | the reference version's database or another PostgreSQL uses port 5432 | stop it: ./Run.ps1 db-stop in the reference folder |
Self-check questions
- Why does the repository pin the SDK version in
global.json? What doesrollForward: latestFeatureallow? - How do the projects of a solution enforce the direction of the layers? Why can Chatex.Api still use the types of Chatex.Data?
- How does a setting in
Directory.Build.propsreach every project? - What does
Nullablechange in the meaning ofstringandstring?? - Why are warnings treated as errors? What problem does this prevent in a team?
- What is the difference between the analyzer rules
CA…and the style rulesIDE…? Where is a rule switched off, and what must accompany such a change? - What problem does Central Package Management solve? Where is the version of a package written, and where is the reference?
- Why does PostgreSQL run in a container rather than as a system service? Where are its data kept, and how do you delete them?
- Why is
dotnet-efinstalled as a local tool? - What does
Invoke-StepinRun.ps1check after each program, and why is that check necessary?
Exercises
- A new command. Add the command
psqltoRun.ps1that opens an interactivepsqlsession in the database container (docker compose exec postgres psql -U postgres -d chatex). Remember to add it toValidateSetand to$Commands. - See the analyzers at work. Add a class with a method
public string Upper(string s) => s.ToUpper();to Chatex.Core and build. Three analyzer rules fail the build (CA1304,CA1311,CA1822). Read what each one says, then fix the code instead of switching the rules off. (Hint: string operations that depend on the culture of the computer, and members that use no instance data.) Delete the class afterwards. - Break the audit. In a scratch copy of the repository, add
System.Text.Jsonversion8.0.0toDirectory.Packages.props, reference it from Chatex.Core and rundotnet restore. Read theNU1903error: which vulnerability does it link to? Then undo the change.