Template
Introduces detailed instructions for ASP.NET API, C#, Docker, MSBuild, testing, and library creation. These guidelines aim to standardize development practices and improve code quality across the project.
2.4 KiB
2.4 KiB
name, description, argument-hint
| name | description | argument-hint |
|---|---|---|
| new-web-api-project | Scaffold a new ASP.NET web project (API or worker service) with correct structure, launch settings, and Docker integration. Use when: creating a new web API, adding an ASP.NET project, setting up a new web service under src/. | Brief description of the web project (e.g., "REST API for user management", "background worker for email processing") |
New Web Project
When to Use
- Creating a new ASP.NET web API or worker service under
src/ - Adding a web project that will be deployed via Docker
Procedure
- Ask the user for the project's purpose and type (API or worker).
- Create the project under
src/{ProjectName}/using the appropriate SDK (Microsoft.NET.Sdk.WeborMicrosoft.NET.Sdk.Worker). - Single target framework — web projects target only the current LTS (no multi-targeting).
- Create
Properties/launchSettings.jsonwithhttpandhttpsprofiles:- Pick ports that do not conflict with existing projects — check all
src/*/Properties/launchSettings.jsonfiles first. - Set
launchBrowser: false. - Set
ASPNETCORE_ENVIRONMENT: Development.
- Pick ports that do not conflict with existing projects — check all
- For APIs: use Minimal APIs with OpenAPI support (
Microsoft.AspNetCore.OpenApi). The OpenAPI document generation and Spectral linting are handled automatically by the build infrastructure. - Create a matching test project under
tests/{ProjectName}.Tests/. - Add both projects to
Solution.slnx. - Add a compose service entry to
compose.yaml(or create one fromdocker/compose.sample.yaml):- Set
RUNTIME_BASE: webfor APIs,RUNTIME_BASE: appfor workers. - Set
PUBLISHED_PROJECTto the project name. - Build context is the repo root with
dockerfile: docker/Dockerfile.
- Set
- Verify the build compiles cleanly.
Launch Settings Template
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:{HTTP_PORT}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:{HTTPS_PORT};http://localhost:{HTTP_PORT}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}