|
| 1 | +# VS Code Debugging Guide for smtp4dev |
| 2 | + |
| 3 | +This document explains how to use the enhanced debugging setup for smtp4dev in VS Code. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +The smtp4dev application uses an integrated development setup where: |
| 8 | +- **ASP.NET Core backend** runs on http://localhost:5000 |
| 9 | +- **Vite dev server** is automatically launched by the .NET app on port 5173 (in development mode only) |
| 10 | +- **Vue CLI middleware** proxies frontend requests from :5000 to the Vite dev server |
| 11 | +- **All debugging happens through the single :5000 endpoint** |
| 12 | + |
| 13 | +## Available Debug Configurations |
| 14 | + |
| 15 | +### Individual Configurations |
| 16 | + |
| 17 | +1. **`.NET Core Launch (web)`** - Debug the ASP.NET Core backend |
| 18 | + - Starts the server on http://localhost:5000 |
| 19 | + - Automatically launches Vite dev server on port 5173 in development mode |
| 20 | + - Includes server-ready action to automatically open browser |
| 21 | + |
| 22 | +2. **`Attach to .NET Core`** - Attach to a running .NET process |
| 23 | + - Useful when the server is already running |
| 24 | + |
| 25 | +3. **`Chrome (Client Debug)`** - Debug client-side code in Chrome |
| 26 | + - Connects to http://localhost:5000 (which proxies to Vite) |
| 27 | + - Enables TypeScript/Vue.js debugging with source maps |
| 28 | + |
| 29 | +4. **`Chrome (Full App)`** - Debug the production build in Chrome |
| 30 | + - Tests the production build with source maps |
| 31 | + |
| 32 | +5. **`Edge (Client Debug)`** - Alternative browser for client debugging |
| 33 | + - Same as Chrome but uses Microsoft Edge |
| 34 | + |
| 35 | +### Compound Configurations (Recommended) |
| 36 | + |
| 37 | +1. **`Full Stack (Development)`** ⭐ **RECOMMENDED** |
| 38 | + - Starts .NET Core backend (which auto-starts Vite dev server) |
| 39 | + - Opens Chrome for both server and client debugging |
| 40 | + - Best for full-stack development with hot reload |
| 41 | + |
| 42 | +2. **`Full Stack (Production Build)`** |
| 43 | + - Builds client assets and starts .NET Core backend |
| 44 | + - Tests the production build |
| 45 | + |
| 46 | +3. **`Full Stack (Edge)`** |
| 47 | + - Same as development but uses Microsoft Edge |
| 48 | + |
| 49 | +## How to Use |
| 50 | + |
| 51 | +### For Full-Stack Development (Most Common) |
| 52 | + |
| 53 | +1. Open VS Code in the smtp4dev repository root |
| 54 | +2. Press `F5` or go to Run and Debug → "Full Stack (Development)" |
| 55 | +3. Wait for the .NET server to start (it will auto-launch Vite) |
| 56 | +4. Chrome will open automatically at http://localhost:5000 |
| 57 | +5. Set breakpoints in both C# (.cs files) and TypeScript/Vue (.ts/.vue files) |
| 58 | + |
| 59 | +### Development Workflow |
| 60 | + |
| 61 | +1. **Backend Changes**: Edit C# files → breakpoints work immediately |
| 62 | +2. **Frontend Changes**: Edit Vue/TS files → hot reload updates the browser automatically |
| 63 | +3. **API Testing**: All requests go through http://localhost:5000 |
| 64 | + |
| 65 | +### Port Configuration |
| 66 | + |
| 67 | +- **Backend (.NET)**: http://localhost:5000 (main entry point) |
| 68 | +- **Frontend (Vite)**: http://127.0.0.1:5173 (auto-started, proxied by backend) |
| 69 | +- **Debugging**: Always use http://localhost:5000 |
| 70 | + |
| 71 | +### Debugging Features |
| 72 | + |
| 73 | +- **Source Maps**: Both client and server debugging with full source map support |
| 74 | +- **Hot Reload**: Frontend changes update immediately without losing state via Vite integration |
| 75 | +- **Breakpoints**: Set breakpoints in TypeScript, Vue components, and C# code |
| 76 | +- **Multiple Browsers**: Separate debug profiles for Chrome and Edge |
| 77 | +- **Console Debugging**: Full access to browser and server console output |
| 78 | +- **Integrated Architecture**: Single entry point (localhost:5000) handles everything |
| 79 | + |
| 80 | +## Troubleshooting |
| 81 | + |
| 82 | +### Port Already in Use |
| 83 | +If you get port conflicts: |
| 84 | +- Stop other instances of the application |
| 85 | +- Check for running dotnet processes: `Get-Process dotnet` (PowerShell) |
| 86 | +- Port 5173 conflicts: The .NET app manages Vite, so stop the .NET process |
| 87 | + |
| 88 | +### Windows-Specific Issues |
| 89 | +- The application automatically handles cross-platform Vite launching |
| 90 | +- No need to manually start Vite - it's integrated into the .NET startup process |
| 91 | + |
| 92 | +### Source Maps Not Working |
| 93 | +- Ensure the .NET application is running (it manages the Vite dev server) |
| 94 | +- Check the browser's Developer Tools → Sources tab |
| 95 | +- Verify TypeScript compilation is successful |
| 96 | + |
| 97 | +### Frontend Not Updating |
| 98 | +- Check that hot reload is working (should see updates automatically) |
| 99 | +- Ensure you're browsing to http://localhost:5000 (not 5173 directly) |
| 100 | +- The .NET app proxies requests to Vite automatically |
| 101 | + |
| 102 | +### Backend API Not Responding |
| 103 | +- Ensure the .NET Core backend is running on port 5000 |
| 104 | +- Check the Debug Console for any startup errors |
| 105 | +- Verify appsettings.json configuration |
| 106 | + |
| 107 | +## Tips |
| 108 | + |
| 109 | +1. **Use "Full Stack (Development)" for daily development** - it provides the best experience |
| 110 | +2. **Always browse to localhost:5000** - this is the integrated entry point |
| 111 | +3. **Set breakpoints before starting debugging** - they'll be hit as soon as the code runs |
| 112 | +4. **Use the integrated terminal** - you can see both .NET and Vite output |
| 113 | +5. **Browser DevTools** - Use alongside VS Code debugging for complete frontend inspection |
| 114 | +6. **Stop All** - Use Ctrl+Shift+F5 to stop all debug sessions at once |
| 115 | +7. **Don't manually start Vite** - let the .NET app handle it automatically |
| 116 | + |
| 117 | +## File Structure for Debugging |
| 118 | + |
| 119 | +``` |
| 120 | +.vscode/ |
| 121 | +├── launch.json # Debug configurations |
| 122 | +├── tasks.json # Build and preparation tasks |
| 123 | +├── settings.json # VS Code settings for better debugging |
| 124 | +└── DEBUG.md # This file |
| 125 | +
|
| 126 | +Rnwood.Smtp4dev/ |
| 127 | +├── ClientApp/ |
| 128 | +│ ├── vite.config.js # Updated with proxy and source map config |
| 129 | +│ └── src/ # Frontend source files |
| 130 | +└── *.cs # Backend source files |
| 131 | +``` |
0 commit comments