English
The solution and projects
Step 1. Create the repository
Why. Version control is the first thing to set up, not the last: every later step can then be undone, compared and explained by its commit.
Do. Create an empty folder for your project and a Git repository in it. The tutorial uses D:\Work\Chatex; choose any path without spaces and non-Latin letters, because some tools still handle such paths badly.
powershell
mkdir D:\Work\Chatexpowershell
cd D:\Work\Chatexpowershell
git initFrom now on, every command runs in this folder, the repository root, unless a step says otherwise.
Step 2. Pin the SDK version
Why. The dotnet command uses the newest SDK installed on the computer. A newer SDK can bring new analyzer warnings or a different default behaviour, so the same code would build on one computer and fail on another. The file global.json pins the SDK for everything under the folder where it lies.
Do. Create the file with the dotnet new template:
powershell
dotnet new globaljson --sdk-version 10.0.403 --roll-forward latestFeaturerollForward: latestFeature allows any SDK of the 10.0 line from 10.0.403 up (10.0.404, 10.0.500, ...), so you do not have to install exactly 10.0.403, but the major version stays 10. Then add the test section by hand; it switches dotnet test to the new Microsoft Testing Platform, which we use from topic 6:
json
{
"sdk": {
"rollForward": "latestFeature",
"version": "10.0.403"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}Check
dotnet --version run in the repository root prints a version of the 10.0 line, even if a newer SDK (for example .NET 11) is installed.
Step 3. Create the solution
Why. A solution groups the projects of an application so that one command builds them all and the IDE opens them together. .NET 10 creates solutions in the new XML format .slnx, which is short, readable and easy to merge, unlike the old .sln.
Do.
powershell
dotnet new sln -n ChatexThe command creates Chatex.slnx with an empty <Solution> element.
Step 4. Create the three projects
Why. Each layer from topic 1 becomes a separate project. Projects make the layer boundaries real: a class in one project can use a class in another only if the first project references the second, so the compiler enforces the direction Api → Core → Data. All source projects live in the folder Source/, the test projects later go to Tests/.
Do. Two class libraries and one ASP.NET Core application:
powershell
dotnet new classlib -o Source/Chatex.Datapowershell
dotnet new classlib -o Source/Chatex.Corepowershell
dotnet new web -o Source/Chatex.ApiThe classlib template adds an empty Class1.cs to each library; delete it:
powershell
Remove-Item Source/Chatex.Data/Class1.cs, Source/Chatex.Core/Class1.csAdd the projects to the solution:
powershell
dotnet sln add Source/Chatex.Data Source/Chatex.Core Source/Chatex.ApiAnd add the references between the layers — Core uses Data, Api uses Core:
powershell
dotnet add Source/Chatex.Core reference Source/Chatex.Datapowershell
dotnet add Source/Chatex.Api reference Source/Chatex.CoreThe solution file now lists the three projects in a solution folder named after their directory:
xml
<Solution>
<Folder Name="/Source/">
<Project Path="Source/Chatex.Api/Chatex.Api.csproj" />
<Project Path="Source/Chatex.Core/Chatex.Core.csproj" />
<Project Path="Source/Chatex.Data/Chatex.Data.csproj" />
</Folder>
</Solution>Why Api does not reference Data directly
Chatex.Api uses only Chatex.Core. It still can use the types of Chatex.Data, because project references are transitive: Api → Core → Data. We could forbid that, but Chatex keeps it simple: the endpoints never call repositories by convention, and the code review (and this tutorial) keeps it that way.
Step 5. Fix the ports of the API
Why. The web template chooses random ports for the application. Chatex uses fixed ones: the Angular development server (topic 15), the .http request files and the documentation all expect the API at http://localhost:5214.
Do. Open Source/Chatex.Api/Properties/launchSettings.json and change the two applicationUrl values:
json
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5214",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7170;http://localhost:5214",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}A launch profile is a named set of settings for dotnet run and the IDE. The http profile is the one we use; the environment variable ASPNETCORE_ENVIRONMENT=Development makes ASP.NET Core read appsettings.Development.json and show detailed errors.
The template also created a minimal Program.cs, which we replace in topic 12:
cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();Check
powershell
dotnet buildThe output ends with Build succeeded. Then run the API:
powershell
dotnet run --project Source/Chatex.Api --launch-profile httpThe console prints Now listening on: http://localhost:5214, and the browser shows Hello World! at that address. Stop the application with Ctrl+C.
Step 6. Tell Git what to ignore
Why. A build creates the folders bin/ and obj/ in every project; npm creates node_modules/; the API will write uploaded files to .uploads/. These files are generated or local and must not get into the repository. Secrets (environment files, certificates) must never get there either.
Do. Download the .gitignore of the reference repository into the repository root:
powershell
Invoke-WebRequest https://raw.githubusercontent.com/musicvano/Chatex/27c83c6932b902c8d8dcef01e30a3dd32c5be05f/.gitignore -OutFile .gitignoreIts first part lists what is specific to Chatex; the long rest is the standard list of the dotnet new gitignore template:
sh
# Chatex: repository-wide ignores.
# .NET build output is covered in detail by the `dotnet new gitignore` section at the end.
# --- Secrets and local configuration ---
.env
.env.*
!.env.example
*.env
appsettings.*.local.json
*.pfx
*.key
# ...
# --- Local data ---
.uploads/
*.dump
# --- .NET ---
bin/
obj/
TestResults/
# ...
# --- Node / Angular (Source/Chatex.Web/) ---
node_modules/
dist/
.angular/
# ...Line endings. Windows ends text lines with two characters (CR LF), Linux and macOS with one (LF). If each developer commits their own endings, every line looks changed in the history, and shell scripts with CR LF fail on the Linux server. The file .gitattributes tells Git to store LF in the repository and in the working folder:
sh
# Normalize all text files to LF, in the repository and in the working tree.
* text=auto eol=lf
# Windows-only scripts need CRLF to run correctly.
*.cmd text eol=crlf
*.bat text eol=crlf
# Binary files: never touch line endings or diff as text.
*.png binary
*.jpg binary
# ...
*.dll binary
*.exe binaryCreate it with these lines (the full list of binary types is in the reference file).
Check
powershell
git status --shortThe list contains .gitattributes, .gitignore, Chatex.slnx, global.json and Source/, but no bin/ or obj/ folders.
We commit at the end of the topic, after the build settings are in place.