Skip to main content

Installation Guide

This guide will walk you through setting up MvcCore Utilidades in your development environment.

Prerequisites

Ensure you have these prerequisites installed before proceeding:
  • .NET 10.0 SDK - Download here
  • Visual Studio 2022 (recommended) or Visual Studio Code with C# extension
  • Git (optional, for cloning the repository)

Verify .NET Installation

1

Check .NET Version

Open your terminal and verify .NET 10.0 is installed:
dotnet --version
You should see version 10.0.x or higher.
2

List Installed SDKs

Confirm .NET 10.0 SDK is available:
dotnet --list-sdks

Project Setup

1

Clone or Create Project

Clone the repository or create a new project directory:
# Clone from repository
git clone <your-repository-url>
cd MvcCoreUtilidades

# Or create new directory
mkdir MvcCoreUtilidades
cd MvcCoreUtilidades
2

Restore NuGet Packages

Restore all required dependencies:
dotnet restore
This will install:
  • Microsoft.Extensions.Caching.Memory (v10.0.3)
3

Build the Project

Compile the application:
dotnet build
Verify the build completes without errors.

Project Configuration

The project uses a minimal configuration approach. Here’s the .csproj file structure:
MvcCoreUtilidades.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\images\" />
    <Folder Include="wwwroot\facturas\" />
    <Folder Include="wwwroot\uploads\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.3" />
  </ItemGroup>
</Project>

Key Configuration Points

The project targets .NET 10.0 (net10.0) with nullable reference types enabled for better null safety.
Three directories are pre-configured under wwwroot/:
  • images/ - For uploaded images
  • facturas/ - For invoice documents
  • uploads/ - For general file uploads
These directories are created automatically at build time.
Only one external package is required:
  • Microsoft.Extensions.Caching.Memory (v10.0.3) - For in-memory caching

Application Startup Configuration

The Program.cs file configures all services and middleware. Here’s the complete setup:
Program.cs
using MvcCoreUtilidades.Repositories;
using MvcNetCoreUtilidades.Helpers;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

// Session configuration
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession();

// Memory caching
builder.Services.AddMemoryCache();

// Register custom services
builder.Services.AddSingleton<HelperPathProvider>();
builder.Services.AddTransient<RepositoryCoches>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();

app.MapStaticAssets();
app.UseSession();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=UploadFiles}/{action=SubirFile}/{id?}")
    .WithStaticAssets();

app.Run();

Service Registration Explained

MVC Services

AddControllersWithViews() - Registers MVC services with Razor view support

Session Services

AddDistributedMemoryCache() + AddSession() - Enables session state management

Memory Cache

AddMemoryCache() - Registers IMemoryCache for in-memory caching

Custom Services

  • HelperPathProvider (Singleton) - File path resolution
  • RepositoryCoches (Transient) - Data access layer
Service Lifetimes:
  • Singleton: HelperPathProvider - Single instance shared across the application
  • Transient: RepositoryCoches - New instance created for each request

Email Configuration (Optional)

If you plan to use the email functionality, configure SMTP settings in appsettings.json:
appsettings.json
{
  "MailSettings": {
    "Credentials": {
      "User": "[email protected]",
      "Password": "your-password"
    }
  },
  "Server": {
    "Host": "smtp.gmail.com",
    "Port": 587,
    "Ssl": true,
    "DefaultCredentials": false
  }
}
Security Best Practice: Never commit credentials to source control. Use:
  • User Secrets for development: dotnet user-secrets set "MailSettings:Credentials:Password" "your-password"
  • Environment variables or Azure Key Vault for production
# Initialize user secrets
dotnet user-secrets init

# Set email credentials
dotnet user-secrets set "MailSettings:Credentials:User" "[email protected]"
dotnet user-secrets set "MailSettings:Credentials:Password" "your-app-password"

# Set SMTP server settings
dotnet user-secrets set "Server:Host" "smtp.gmail.com"
dotnet user-secrets set "Server:Port" "587"
dotnet user-secrets set "Server:Ssl" "true"
dotnet user-secrets set "Server:DefaultCredentials" "false"

Running the Application

1

Start the Development Server

Run the application:
dotnet run
Or with hot reload:
dotnet watch run
2

Access the Application

Open your browser and navigate to:
https://localhost:5001
or
http://localhost:5000
The application will launch with the file upload page (default route: UploadFiles/SubirFile).
3

Verify Installation

Test that all features work:
  • Navigate to different controllers
  • Upload a test file
  • Try session management (login/logout)
  • Test caching functionality

Troubleshooting

If ports 5000/5001 are occupied, modify launchSettings.json or specify a different port:
dotnet run --urls="https://localhost:7001;http://localhost:7000"
Ensure the wwwroot directories have write permissions:
# On Linux/Mac
chmod -R 755 wwwroot/

# On Windows (PowerShell as Administrator)
icacls wwwroot /grant Users:(OI)(CI)F /T
Verify these two services are registered in Program.cs:
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession();
And middleware is configured:
app.UseSession(); // Must be after UseRouting()
Common issues:
  • Gmail: Enable “Less secure app access” or use App Passwords with 2FA
  • Authentication: Ensure UseDefaultCredentials = false is set BEFORE setting credentials
  • Firewall: Check that outbound port 587 (or 465 for SSL) is open

Development Environment Setup

Visual Studio 2022

  1. Open MvcCoreUtilidades.sln (if available) or open folder
  2. Visual Studio will automatically restore NuGet packages
  3. Press F5 to run with debugging or Ctrl+F5 without debugging

Visual Studio Code

  1. Install the C# Dev Kit extension
  2. Open the project folder
  3. Press F5 to launch with debugger
  4. Or use integrated terminal:
    dotnet run
    

Next Steps

Quick Start Guide

Now that you have the project set up, learn how to use the utilities with practical examples

Build docs developers (and LLMs) love