Logo

Using envvault with .NET

Note: Please ensure that you have completed the previous steps

Prerequisites

  • .NET SDK installed
  • envvault CLI tool installed
  • An existing .NET project

Usage

Running Your Application

To run your .NET application with environment variables from envvault:

$ envvault run --env=dev dotnet run

Caching Environment Variables

For better performance, you can cache your environment variables:

$ envvault run --env=dev -c -- dotnet run

Example Implementation

Here is how to set up a basic .NET application with envvault:

// Program.cs
var builder = WebApplication.CreateBuilder(args);

// Your environment variables are automatically loaded
var port = Environment.GetEnvironmentVariable("PORT") ?? "5000";
var dbUrl = Environment.GetEnvironmentVariable("DB_URL");

var app = builder.Build();

app.MapGet("/", () => "Hello from envvault!");

app.Run($"http://localhost:{port}");

// appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "$DB_URL"
  },
  "Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://localhost:$PORT"
      }
    }
  }
}