VS Command Server
A Visual Studio extension that provides an HTTP server to execute commands from external applications.
This is a port of VSCode Command Server using the exact same REST API.
Features
- 🚀 HTTP Server: Exposes Visual Studio commands via REST API
- 🔧 Command Execution: Execute any Visual Studio command remotely
- 📝 Command Discovery: Get list of all available commands
- 📊 Server Info: Monitor server status and workspace information
Usage
Starting the Server
The server can automatically start when Visual Studio loads. You can also manually control it from the Tools menu:
- Tools → Start Command Server - Start the HTTP server
- Tools → Stop Command Server - Stop the HTTP server
- Tools → Show Command Server Status - Check if server is running
The server starts on port 3000 by default (or next available port).
API Endpoints
GET / - Server Status
Check if the server is running.
curl http://localhost:3000/
Response:
{
"success": true,
"result": "VS Command Server is running"
}
Get server details including port, PID, solution path, and VS version.
curl http://localhost:3000/info
Response:
{
"success": true,
"port": 3000,
"processId": 12345,
"solutionPath": "C:\\Projects\\MySolution.sln",
"visualStudioVersion": "Visual Studio 18.0 (Community)"
}
GET /commands - List Available Commands
Get all available Visual Studio commands.
curl http://localhost:3000/commands
Response:
{
"success": true,
"commands": [
{ "name": "File.NewFile", "displayName": "New File" },
{ "name": "File.SaveAll", "displayName": "Save All" },
...
]
}
POST /execute - Execute Command
Execute a Visual Studio command with optional arguments.
curl -X POST http://localhost:3000/execute \
-H "Content-Type: application/json" \
-d '{"command": "File.NewFile"}'
With arguments:
curl -X POST http://localhost:3000/execute \
-H "Content-Type: application/json" \
-d '{"command": "File.OpenFile", "args": ["C:\\Projects\\file.cs"]}'
Response:
{
"success": true,
"command": "File.NewFile",
"result": "Command 'File.NewFile' executed successfully"
}
Client Examples
Python Client
import requests
BASE_URL = "http://localhost:3000"
# Check status
response = requests.get(f"{BASE_URL}/")
print(response.json())
# Get server info
response = requests.get(f"{BASE_URL}/info")
print(response.json())
# List commands
response = requests.get(f"{BASE_URL}/commands")
commands = response.json()["commands"]
print(f"Found {len(commands)} commands")
# Execute a command
response = requests.post(
f"{BASE_URL}/execute",
json={"command": "View.SolutionExplorer"}
)
print(response.json())
PowerShell Client
# Check status
Invoke-RestMethod -Uri "http://localhost:3000/"
# Get server info
Invoke-RestMethod -Uri "http://localhost:3000/info"
# Execute command
$body = @{ command = "File.NewFile" } | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:3000/execute" -Method Post -Body $body -ContentType "application/json"
curl Examples
# Check status
curl http://localhost:3000/
# Get server info
curl http://localhost:3000/info
# List all commands
curl http://localhost:3000/commands
# Execute command
curl -X POST http://localhost:3000/execute \
-H "Content-Type: application/json" \
-d '{"command": "View.SolutionExplorer"}'
Common Visual Studio Commands
Here are some useful commands you can execute:
| Command |
Description |
File.NewFile |
Create a new file |
File.OpenFile |
Open file dialog |
File.SaveAll |
Save all files |
File.CloseDocument |
Close current document |
Edit.Undo |
Undo last action |
Edit.Redo |
Redo last action |
Edit.Find |
Open Find dialog |
Edit.GoTo |
Go to line |
View.SolutionExplorer |
Show Solution Explorer |
View.ErrorList |
Show Error List |
View.Output |
Show Output window |
View.TerminalWindow |
Open Terminal |
Build.BuildSolution |
Build entire solution |
Build.RebuildSolution |
Rebuild entire solution |
Build.CleanSolution |
Clean solution |
Debug.Start |
Start debugging |
Debug.StartWithoutDebugging |
Run without debugger |
Debug.StopDebugging |
Stop debugging |
Debug.ToggleBreakpoint |
Toggle breakpoint |
Tools.Options |
Open Options dialog |
All API responses follow this format:
{
"success": true,
"result": "Result data (if any)",
"command": "executed.command.name",
"error": "Error message (if failed)"
}
Security Notes
- The server only accepts connections from localhost (127.0.0.1)
- CORS is enabled for development convenience
- Consider security implications before exposing to external networks
Requirements
- Visual Studio 2022 (version 17.0 or later)
- .NET Framework 4.8
License
MIT License