Lemworks.Generators.Configuration 0.0.3

dotnet add package Lemworks.Generators.Configuration --version 0.0.3
                    
NuGet\Install-Package Lemworks.Generators.Configuration -Version 0.0.3
                    
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="Lemworks.Generators.Configuration" Version="0.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lemworks.Generators.Configuration" Version="0.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Lemworks.Generators.Configuration" />
                    
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 Lemworks.Generators.Configuration --version 0.0.3
                    
#r "nuget: Lemworks.Generators.Configuration, 0.0.3"
                    
#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.
#addin nuget:?package=Lemworks.Generators.Configuration&version=0.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Lemworks.Generators.Configuration&version=0.0.3
                    
Install as a Cake Tool

Lemworks.Generators.Configuration

Latest version License: MIT NuGet Downloads

Source-generated configuration keys from your appsettings.json

Setup

Install the package

dotnet add package Lemworks.Generators.Configuration

Add the following to your .csproj file

<ItemGroup>
    <AdditionalFiles Include="appsettings.json" />
    <Content Include="appsettings.json" CopyToOutputDirectory="Always" /> 
</ItemGroup>

Create an appsettings.json file with some content

{
  "ConnectionStrings": {
    "SqlServer": "Server=(localdb)\\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning"
    }
  }
}

The keys will be generated as const strings in a AppSettings class

using System;

namespace Generated.Configuration
{
    public static class AppSettings
    {
        public static class ConnectionStrings
        {
            public const string SqlServer = "ConnectionStrings:SqlServer";
        }
        
        public static class Logging
        {
            public static class LogLevel
            {
                public const string Default = "Logging:LogLevel:Default";
                public const string Microsoft = "Logging:LogLevel:Microsoft";
            }
        }
    }
}

Use the keys in your code like this

using Generated.Configuration;

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();
        
configuration.GetConnectionString(AppSettings.ConnectionStrings.SqlServer) // "Server=(localdb)\\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True"
configuration[AppSettings.Logging.LogLevel.Default] // "Information"
configuration[AppSettings.Logging.LogLevel.Microsoft] // "Warning"
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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.0.3 138 5/19/2025
0.0.2 165 5/16/2025
0.0.1 171 5/16/2025