When deploying CMS 12/Commerce 14 (NET 6) in DXP, it is recommended to install EPiServer.CloudPlatform.Cms package and
call
public void ConfigureServices(
IServiceCollection services,
IConfiguration configuration,
IWebHostEnvironment env)
{
...
if (!env.IsDevelopment())
{
services.AddCmsCloudPlatformSupport(configuration);
}
}
in ConfigureServices method in the Startup.cs file.
This method will inject DXP (Azure App Service) configurations to the configuration variable for later usage.
However, the program.cs file and startup.cs files might have heavy customization and exceptions like "EPiServer.Data.DataInitialization failed", and "Microsoft.Data.SqlClient.SqlException" will be thrown when the app service could not find the needed Azure SQL database/ Azure blob after AddCmsCloudPlatformSupport is called in DXP environments.
There is a trick that can debug the AddCmsCloudPlatformSupport locally without trial-and-error deployment attempts to DXP.
Create a launch profile for the integration environment (similar to the DXP Integration environment).
{"profiles": {"FakeDXP": {"commandName": "Project","launchBrowser": true,"environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Integration","CONNECTIONSTRINGS__EPISERVERAZUREBLOBS": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;","CONNECTIONSTRINGS__EPISERVERDB": "Data Source=(LocalDb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\QuickSilver.mdf;Initial Catalog=QuickSilver;Integrated Security=True;Connect Timeout=30","CONNECTIONSTRINGS__ECFSQLCONNECTION": "Data Source=(LocalDb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\QuickSilver.Commerce.mdf;Initial Catalog=QuickSilver.Commerce;Integrated Security=True;Connect Timeout=30"
},"applicationUrl": "https://localhost:5000/"
}
}
}
In the configuration, the Azure blob connection string is emulated by Azurite.
Set services.AddEventProvider() in the Startup.cs file as there is no way to emulate Azure Service Bus locally.
public void ConfigureServices(
IServiceCollection services,
IConfiguration configuration,
IWebHostEnvironment env)
{
...
if (!env.IsDevelopment())
{
services.AddCmsCloudPlatformSupport(configuration);
services.AddEventProvider<NullEventProvider>():
}
}
After the AddCmsCloudPlatformSupport function is called, connection strings from the environment variables can be debugged and verified if they have been injected properly.