Settings.CodeGen 1.0.0

dotnet add package Settings.CodeGen --version 1.0.0
                    
NuGet\Install-Package Settings.CodeGen -Version 1.0.0
                    
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="Settings.CodeGen" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Settings.CodeGen" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Settings.CodeGen">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 Settings.CodeGen --version 1.0.0
                    
#r "nuget: Settings.CodeGen, 1.0.0"
                    
#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 Settings.CodeGen@1.0.0
                    
#: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=Settings.CodeGen&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Settings.CodeGen&version=1.0.0
                    
Install as a Cake Tool

Settings.CodeGen

Generates strongly-typed constants for appsettings.json(appsettings.{Environment}.json) configuration keys. This helps prevent typos and improves refactorability when accessing configuration values.

Usage

  1. Install the package:
dotnet add package Settings.CodeGen
  1. Build your project. Constants will be generated automatically in the Generated folder (relative to the project file).
  2. Use the generated keys in your code:
string conn = configuration[AppSettingsKeys.ConnectionStrings.DefaultConnection];

Configuration

You can configure the code generation by adding properties to your project file (.csproj).

Add a <PropertyGroup> and set the desired properties:

<PropertyGroup>
  
  <SettingsCodeGenNamespace>MyApp.Config</SettingsCodeGenNamespace>

  
  <SettingsCodeGenProjectDir>/src/projectWithAppsettingFiles</SettingsCodeGenProjectDir>

  
  <SettingsCodeGenLocalization>en</SettingsCodeGenLocalization>

  
  <SettingsCodeGenEnabled>false</SettingsCodeGenEnabled>
</PropertyGroup>

Minimal Configuration Examples

To use defaults (generate in $(MSBuildProjectName).Generated.AppSettingsKeys):

No configuration needed. Just install the package and build.

To disable generation for a specific project:

<PropertyGroup>
  <SettingsCodeGenEnabled>true</SettingsCodeGenEnabled>
</PropertyGroup>

To change the output namespace:

<PropertyGroup>
  <SettingsCodeGenNamespace>MyCompany.MyApp.Configuration</SettingsCodeGenNamespace>
</PropertyGroup>
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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
1.0.0 88 7/27/2025