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" />
<PackageReference Include="Lemworks.Generators.Configuration" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Lemworks.Generators.Configuration&version=0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Lemworks.Generators.Configuration
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.