.NET WebAPI Auto Start
Overview
This skill automatically checks if a .NET WebAPI service is running after the agent completes work on a .NET WebAPI project. If the service is not running, it offers to start it and open the Scalar API documentation in the browser.
When to Use
This skill activates automatically at the end of agent work when:
- The agent has been modifying a .NET WebAPI project
- The workspace contains a
.csproj file with ASP.NET Core references
- The project has a
launchSettings.json file (or Properties/launchSettings.json)
Workflow
Follow these steps sequentially at the end of agent work:
Step 1: Detect .NET WebAPI Project
- Search for
.csproj files in the workspace root
- Read the
.csproj file to verify it contains ASP.NET Core references:
- Look for Microsoft.AspNetCore.App framework reference - Or Microsoft.AspNetCore.App package reference - Or Microsoft.NET.Sdk.Web SDK
- If no WebAPI project is found, skip this workflow
- Search for
launchSettings.json in:
- Properties/launchSettings.json (preferred location) - launchSettings.json (root directory)
Step 2: Determine Launch Profile
- Read and parse
launchSettings.json as JSON
- Extract the
profiles object
- Select a launch profile in this priority order:
- Profile named "http" (if exists) - Profile named "https" (if exists) - First profile in the profiles object
- Extract the base URL:
- If launchUrl exists, use it as-is (it may already include a path) - Otherwise, extract the first URL from applicationUrl (split by semicolon if multiple URLs) - If applicationUrl contains multiple URLs separated by semicolons, prefer HTTP over HTTPS for faster startup
- Construct the Scalar URL:
- If launchUrl exists and doesn't end with /scalar, replace it with /scalar - If no launchUrl, append /scalar to the base URL from applicationUrl - Example: http://localhost:5000 → http://localhost:5000/scalar
Step 3: Check if Service is Running
- Extract the port number from the base URL (from Step 2)
- Try to check if the service is running using one of these methods:
Method A: HTTP Request (preferred) - Use curl -f --max-time 2 <base-url> or similar HTTP request - If the request succeeds (exit code 0), the service is running - If it fails or times out, the service is not running
Method B: Port Check (fallback) - On macOS/Linux: lsof -i :<port> or netstat -an | grep :<port> - On Windows: netstat -an | findstr :<port> - If port is in use, service may be running (but verify with HTTP request)
- If service is running:
- Inform the user: "The service is already running." - End workflow
Step 4: Ask User
If the service is not running:
- Use the
AskQuestion tool with this question:
- Question: "The service is not running. Would you like to start it and open Scalar documentation?" - Options: ["Yes", "No"]
- If user selects "No":
- End workflow
Step 5: Start Service
If user selects "Yes":
- Determine the launch profile name (from Step 2)
- Run the service in the background:
``bash dotnet run --launch-profile <profile-name> ` - Use runterminalcmd with is_background: true - Run from the directory containing the .csproj` file
- Wait for service startup:
- Wait 3-5 seconds for the service to start - Optionally check if the service is responding (repeat Step 3 check)
- Open browser to Scalar documentation:
- Construct the full Scalar URL (from Step 2) - macOS: open <scalar-url> - Linux: xdg-open <scalar-url> - Windows: start <scalar-url>
- Inform the user:
- "Service started. Opening Scalar documentation in browser."
Edge Cases
No launchSettings.json Found
- HTTP: http://localhost:5000 - HTTPS: https://localhost:5001 (if HTTPS is preferred)
- Use profile name
"http" or "https" when running dotnet run
- If neither profile exists, run
dotnet run without --launch-profile
Multiple Launch Profiles
- Prefer
"http" over "https" for faster startup (no certificate setup)
- If only HTTPS profiles exist, use the first HTTPS profile
- Extract the first URL from
applicationUrl if multiple URLs are present
Service Already Running
- If Step 3 detects the service is running, inform the user and end workflow
- Do not attempt to start another instance
Startup Failure
- If
dotnet run fails, inform the user about the error
- Do not attempt to open the browser if startup failed
- Show the error message from the command output
No .csproj File Found
- Skip this workflow entirely
- Do not prompt the user
Technical Notes
launchSettings.json Structure
{
"profiles": {
"http": {
"commandName": "Project",
"applicationUrl": "http://localhost:5000",
"launchUrl": "swagger"
},
"https": {
"commandName": "Project",
"applicationUrl": "https://localhost:5001",
"launchUrl": "swagger"
}
}
}
Service Check Commands
HTTP Request:
curl -f --max-time 2 http://localhost:5000
Port Check (macOS/Linux):
lsof -i :5000
# or
netstat -an | grep :5000
Port Check (Windows):
netstat -an | findstr :5000
Starting Service
# From project root directory
dotnet run --launch-profile http
Opening Browser
macOS:
open http://localhost:5000/scalar
Linux:
xdg-open http://localhost:5000/scalar
Windows:
start http://localhost:5000/scalar