.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
.csprojfile with ASP.NET Core references - •The project has a
launchSettings.jsonfile (orProperties/launchSettings.json)
Workflow
Follow these steps sequentially at the end of agent work:
Step 1: Detect .NET WebAPI Project
- •Search for
.csprojfiles in the workspace root - •Read the
.csprojfile to verify it contains ASP.NET Core references:- •Look for
Microsoft.AspNetCore.Appframework reference - •Or
Microsoft.AspNetCore.Apppackage reference - •Or
Microsoft.NET.Sdk.WebSDK
- •Look for
- •If no WebAPI project is found, skip this workflow
- •Search for
launchSettings.jsonin:- •
Properties/launchSettings.json(preferred location) - •
launchSettings.json(root directory)
- •
Step 2: Determine Launch Profile
- •Read and parse
launchSettings.jsonas JSON - •Extract the
profilesobject - •Select a launch profile in this priority order:
- •Profile named
"http"(if exists) - •Profile named
"https"(if exists) - •First profile in the profiles object
- •Profile named
- •Extract the base URL:
- •If
launchUrlexists, use it as-is (it may already include a path) - •Otherwise, extract the first URL from
applicationUrl(split by semicolon if multiple URLs) - •If
applicationUrlcontains multiple URLs separated by semicolons, prefer HTTP over HTTPS for faster startup
- •If
- •Construct the Scalar URL:
- •If
launchUrlexists and doesn't end with/scalar, replace it with/scalar - •If no
launchUrl, append/scalarto the base URL fromapplicationUrl - •Example:
http://localhost:5000→http://localhost:5000/scalar
- •If
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>ornetstat -an | grep :<port> - •On Windows:
netstat -an | findstr :<port> - •If port is in use, service may be running (but verify with HTTP request)
- •Use
- •
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
AskQuestiontool 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:
bashdotnet run --launch-profile <profile-name>
- •Use
run_terminal_cmdwithis_background: true - •Run from the directory containing the
.csprojfile
- •Use
- •
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
- •Use default ports:
- •HTTP:
http://localhost:5000 - •HTTPS:
https://localhost:5001(if HTTPS is preferred)
- •HTTP:
- •Use profile name
"http"or"https"when runningdotnet run - •If neither profile exists, run
dotnet runwithout--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
applicationUrlif 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 runfails, 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