This package provides a Kentico Xperience 13.0 custom module to auto-register the ASPNET Core appsettings.json as Xperience's configuration source.
This is useful in Console applications which do not use an IHostBuilder to configure the application.
This package is compatible with ASP.NET Core 3.1 -> ASP.NET Core 5 and is designed to be used with .NET Core / .NET 5 Console applications integrated with Kentico Xperience 13.0.
-
First, install the NuGet package in your ASP.NET Core project
dotnet add package XperienceCommunity.AppSettingsJsonRegistration
-
Create an
appsettings.json
file at the root of your console app project with theCMSConnectionString
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "ConnectionStrings": { "CMSConnectionString": "<your connection string here>" } }
-
Ensure the
appsettings.json
file is configured to copy to the output directory on build by editing your console application's.csproj
file and adding the following (if it doesn't already exist)<ItemGroup> <None Update="appsettings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup>
-
Add the call to
CMSApplication.Init();
at the beginning of yourMain()
methodclass Program { static void Main(string[] args) { CMSApplication.Init(); // ... } }
This package also supports having a appsettings.local.json
which is optional and can be ignored in your source control.
It can also support User Secrets. First add the package to your application:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.11" />
</ItemGroup>
Then right click on your project in Visual Studio and select "Manage User Secrets" to create the secrets file.
Secrets can also be managed for a project, outside of Visual Studio, at the commend line using the .NET CLI.
If you discover a problem, please open an issue.
If you would like contribute to the code or documentation, please open a pull request.