Skip to content

This package provides an Xperience 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.

License

Notifications You must be signed in to change notification settings

wiredviews/xperience-appsettings-json-registration

Repository files navigation

Xperience appsettings.json Registration

GitHub Actions CI: Build

Publish Packages to NuGet

NuGet Package

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.

Dependencies

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.

How to Use?

  1. First, install the NuGet package in your ASP.NET Core project

    dotnet add package XperienceCommunity.AppSettingsJsonRegistration
  2. Create an appsettings.json file at the root of your console app project with the CMSConnectionString

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "ConnectionStrings": {
        "CMSConnectionString": "<your connection string here>"
      }
    }
  3. 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>
  4. Add the call to CMSApplication.Init(); at the beginning of your Main() method

    class 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.

Contributions

If you discover a problem, please open an issue.

If you would like contribute to the code or documentation, please open a pull request.

References

Kentico Xperience

About

This package provides an Xperience 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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published