Your cart is currently empty!
.NET CLI Commands Reference/Cheat Sheet
Core Commands
dotnet build
Builds the project and its dependencies.
# Basic build
dotnet build
# Build in Release mode
dotnet build --configuration Release
# Build specific project
dotnet build MyProject.csproj
# Build with verbose output
dotnet build --verbosity detailed
dotnet run
Builds and runs the application.
# Basic run
dotnet run
# Run with specific configuration
dotnet run --configuration Release
# Run specific project
dotnet run --project MyProject.csproj
Port Specifications
Using --urls Parameter
# Run on specific port
dotnet run --urls "http://localhost:5000"
# Run on multiple ports
dotnet run --urls "http://localhost:5000;https://localhost:5001"
# Run on all interfaces
dotnet run --urls "http://*:5000"
# Run on specific IP
dotnet run --urls "http://192.168.1.100:5000"
Using Environment Variables
# Set ASPNETCORE_URLS environment variable
export ASPNETCORE_URLS="http://localhost:8080"
dotnet run
# Windows Command Prompt
set ASPNETCORE_URLS=http://localhost:8080
dotnet run
# Windows PowerShell
$env:ASPNETCORE_URLS="http://localhost:8080"
dotnet run
Using launchSettings.json
Edit Properties/launchSettings.json:
{
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
Watch Commands
dotnet watch
Automatically rebuilds and restarts the application when files change.
# Basic watch (runs dotnet run)
dotnet watch
# Watch with specific command
dotnet watch run
# Watch build only (no run)
dotnet watch build
# Watch with port specification
dotnet watch run --urls "http://localhost:3000"
# Watch with launch profile
dotnet watch run --launch-profile "Development"
Watch Configuration
Add to your .csproj file:
<PropertyGroup>
  <!-- Files to watch -->
  <DefaultItemExcludes>$(DefaultItemExcludes);wwwroot\lib\**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
  <!-- Additional files to watch -->
  <Watch Include="**\*.cshtml" />
  <Watch Include="**\*.css" />
  <Watch Include="**\*.js" />
</ItemGroup>
Common Development Scenarios
CDIS V2 Development Setup
# Navigate to project directory
cd CDISV2Core
# Development with watch (recommended)
dotnet watch run --urls "http://localhost:5000;https://localhost:5001"
# Production-like testing
dotnet run --configuration Release --urls "http://localhost:8080"
# Build for deployment
dotnet build --configuration Release --output ./publish
Port Conflict Resolution
# Check what's using a port (Windows)
netstat -ano | findstr :5000
# Check what's using a port (Linux/Mac)
lsof -i :5000
# Kill process by PID (Windows)
taskkill /PID 1234 /F
# Kill process by PID (Linux/Mac)
kill -9 1234
Environment-Specific Commands
Development
dotnet watch run --environment Development --urls "http://localhost:5000"
Staging
dotnet run --environment Staging --urls "http://localhost:8080"
Production
dotnet run --environment Production --urls "http://localhost:80"
Useful Flags
| Flag | Description | 
|---|---|
--configuration | Build configuration (Debug/Release) | 
--framework | Target framework | 
--runtime | Target runtime identifier | 
--verbosity | Log verbosity (quiet, minimal, normal, detailed, diagnostic) | 
--no-build | Don’t build before running | 
--no-restore | Don’t restore packages before building | 
--launch-profile | Launch profile to use | 
Quick Reference
# Most common development command
dotnet watch run
# Custom port development
dotnet watch run --urls "http://localhost:3000"
# Production build
dotnet build --configuration Release
# Clean and rebuild
dotnet clean && dotnet build
# Restore packages
dotnet restore
Troubleshooting
Port Already in Use
- Change port: 
dotnet run --urls "http://localhost:5001" - Kill existing process: 
taskkill /F /IM dotnet.exe - Use different launch profile
 
Watch Not Working
- Check file patterns in 
.csproj - Restart with 
dotnet watch clean - Verify file permissions
 
Build Errors
- Clean solution: 
dotnet clean - Restore packages: 
dotnet restore - Check project references: 
dotnet list reference 
by
Tags:
Leave a Reply