A modern web application built with ASP.NET Core 9.0 and Blazor Server components.
๐ Quick Start
Prerequisites
Before you begin, ensure you have the following installed on your Mac:
- .NET 9.0 SDK - Download here
- Git - Usually pre-installed on macOS, or install via Homebrew
- Visual Studio Code (recommended) or Visual Studio for Mac
Installation
-
Clone the repository
git clone <your-repository-url> cd aspnet -
Verify .NET installation
dotnet --version # Should show 9.0.x or higher -
Restore dependencies
dotnet restore -
Build the project
dotnet build -
Run the application
dotnet run --project aspnet -
Open in browser
- Navigate to
https://localhost:5001orhttp://localhost:5000 - The application will automatically open in your default browser
- Navigate to
๐ ๏ธ Development Setup
Recommended VS Code Extensions
Install these extensions for the best development experience:
code --install-extension ms-dotnettools.csharp
code --install-extension ms-dotnettools.blazorwasm-companion
code --install-extension ms-vscode.vscode-json
code --install-extension bradlc.vscode-tailwindcss # If using Tailwind CSS
Or search for these in VS Code Extensions marketplace:
- C# Dev Kit - IntelliSense, debugging, and project management
- Blazor WASM Companion - Enhanced Blazor development
- JSON - JSON file support
- Auto Rename Tag - Automatically rename paired HTML/XML tags
Project Structure
aspnet/
โโโ Components/ # Blazor components
โ โโโ Layout/ # Layout components (MainLayout, NavMenu)
โ โโโ Pages/ # Page components (Home, Counter, Weather)
โ โโโ App.razor # Root component
โ โโโ Routes.razor # Routing configuration
โ โโโ _Imports.razor # Global using statements
โโโ Properties/ # Launch settings
โโโ wwwroot/ # Static files (CSS, JS, images)
โโโ appsettings.json # Application configuration
โโโ Program.cs # Application entry point
โโโ aspnet.csproj # Project file
๐ง Development Commands
Building and Running
dotnet clean
dotnet restore
dotnet build
dotnet run --project aspnet
dotnet watch --project aspnet
dotnet build --configuration Release
dotnet publish --configuration Release --output ./publish
Testing
dotnet test
dotnet test --collect:"XPlat Code Coverage"
dotnet test path/to/test/project
๐ Environment Configuration
Development Settings
The application uses different configuration files for different environments:
appsettings.json- Base configurationappsettings.Development.json- Development overridesappsettings.Production.json- Production overrides (create if needed)
Environment Variables
Set environment variables for local development:
export ASPNETCORE_ENVIRONMENT=Development
export ASPNETCORE_URLS="https://localhost:5001;http://localhost:5000"
echo 'export ASPNETCORE_ENVIRONMENT=Development' >> ~/.zshrc
๐ Debugging
VS Code Debugging
- Open the project in VS Code
- Go to Run and Debug (โงโD)
- Select โ.NET Core Launch (web)โ configuration
- Set breakpoints in your code
- Press F5 to start debugging
Browser Developer Tools
- Chrome DevTools: F12 or Cmd+Option+I
- Blazor debugging: Enable in browser dev tools under Sources tab
๐ฆ Package Management
Adding NuGet Packages
dotnet add aspnet package PackageName
dotnet add aspnet package PackageName --version 1.2.3
dotnet add aspnet package PackageName --package-directory packages
Updating Packages
dotnet list aspnet package --outdated
dotnet add aspnet package PackageName
dotnet add aspnet package PackageName --version "*"
๐ Deployment
Local Production Build
dotnet publish aspnet --configuration Release --output ./dist
cd dist
dotnet aspnet.dll
Docker (Optional)
Create a Dockerfile in the root directory:
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY ["aspnet/aspnet.csproj", "aspnet/"]
RUN dotnet restore "aspnet/aspnet.csproj"
COPY . .
WORKDIR "/src/aspnet"
RUN dotnet build "aspnet.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "aspnet.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "aspnet.dll"]
Build and run with Docker:
docker build -t aspnet-app .
docker run -p 8080:80 aspnet-app
๐ Troubleshooting
Common Issues
-
Port already in use
# Find process using port 5000/5001 lsof -ti:5000 lsof -ti:5001 # Kill process kill -9 <PID> -
Certificate issues (HTTPS)
# Trust development certificate dotnet dev-certs https --trust -
Clear NuGet cache
dotnet nuget locals all --clear -
Reset to clean state
dotnet clean rm -rf bin obj dotnet restore dotnet build
Performance Tips
- Use
dotnet watchfor development to enable hot reload - Enable browser caching for static assets in production
- Use
--configuration Releasefor production builds - Monitor memory usage with
dotnet-counters
๐ Additional Resources
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
-
Christopher KelkerWeb Developer, blogger and gym enthusiast.