FileBasedApp 0.1.2

dotnet add package FileBasedApp --version 0.1.2
                    
NuGet\Install-Package FileBasedApp -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FileBasedApp" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FileBasedApp" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="FileBasedApp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FileBasedApp --version 0.1.2
                    
#r "nuget: FileBasedApp, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FileBasedApp@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FileBasedApp&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=FileBasedApp&version=0.1.2
                    
Install as a Cake Tool

FileBasedApp

A base library for building file-based applications with dependency injection and configuration support.

Features

  • Base classes for building file-based applications
  • Integrated dependency injection using Microsoft.Extensions.DependencyInjection
  • Configuration support with JSON files
  • Built-in logging with console output
  • Support for both synchronous and asynchronous applications

Installation

Install the NuGet package:

dotnet add package FileBasedApp

Usage

Synchronous Application

Save this to HelloWorld.cs.

#:package FileBasedApp@0.1.0

using FileBasedApp;

new HelloWorld()
    .Build()
    .ConfigureServices()
    .Run();

class HelloWorld : FileBasedApplication
{
    public override void Run()
    {
        Console.WriteLine("Hello, World!");
    }
}

Run with dotnet HelloWorld.cs.

Asynchronous Application

Save this to CurrentWeatherApplication.cs.

#:package FileBasedApp@0.1.0

using FileBasedApp;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

await new CurrentWeatherApplication()
    .Build()
    .ConfigureServices()
    .Run();

class CurrentWeatherApplication : AsyncFileBasedApplication
{
    public override void SetupServices()
    {
        // Configure options
        this._serviceCollection.Configure<CurrentWeatherApplicationOptions>(this._configuration.GetSection(nameof(CurrentWeatherApplicationOptions)));

        // Register HttpClient factory
        this._serviceCollection.AddHttpClient();
    }

    public override async Task Run()
    {
        var httpClientFactory = this._serviceProvider.GetRequiredService<IHttpClientFactory>();
        var httpClient = httpClientFactory.CreateClient();
        var logger = this._serviceProvider.GetRequiredService<ILogger<CurrentWeatherApplication>>();
        var options = this._serviceProvider.GetRequiredService<IOptions<CurrentWeatherApplicationOptions>>();

        logger.LogInformation("Application is running.");
        logger.LogInformation("Using Latitude: {Latitude}, Longitude: {Longitude}", options.Value.Latitude, options.Value.Longitude);

        var response = await httpClient.GetAsync($"{options.Value.WeatherApiUrl}?latitude={options.Value.Latitude}&longitude={options.Value.Longitude}&current_weather=true");

        if (response.IsSuccessStatusCode)
        {
            var content = await response.Content.ReadAsStringAsync();
            logger.LogInformation("Received weather data: {@content}", content);
        }
        else
        {
            logger.LogError("Failed to fetch weather data. Status Code: {@statusCode}", response.StatusCode);
        }
    }
}

class CurrentWeatherApplicationOptions
{
    public string Latitude { get; set; } = string.Empty;

    public string Longitude { get; set; } = string.Empty;

    public string WeatherApiUrl { get; set; } = string.Empty;
}

Save this to appsettings.CurrentWeatherApplication.json

{
  "CurrentWeatherApplicationOptions": {
    "Latitude": "40.589169",
    "Longitude": "-111.638812",
    "WeatherApiUrl": "https://api.open-meteo.com/v1/forecast"
  }
}

Building Locally

dotnet restore FileBasedApp/FileBasedApp.csproj
dotnet build FileBasedApp/FileBasedApp.csproj -c Release
dotnet pack FileBasedApp/FileBasedApp.csproj -c Release -o ./artifacts

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 444 11/19/2025
0.1.1 343 11/17/2025
0.1.0 340 11/17/2025