Running DevExpress XtraReports under Linux in App Service with custom fonts
Tags: aspdotnet, azure, azureapp, docker
Published: 2024-03-06 20:18:40

We have the need to convert our years-old SSRS reports to a newer technology to be able to lift a customer's web app to the Azure cloud. I decided to use DevExpress XtraReports, because there is a nice [import feature of existing SSRS reports](https://docs.devexpress.com/XtraReports/1468/get-started-with-devexpress-reporting/convert-third-party-reports-to-devexpress-reports). 

To reduce the overall monthly cost of running the Web App in Azure we decided to use a Azure App Service Linux plan. 
The reports need the use of custom fonts, i.e. for displaying barcodes.
However, running XtraReports under Linux really isn't easy.

I've found several information in the DevExpress documentation and Knowledge Base. Though, some information was outdated and didn't work, so my journey was like an adventure.
Two years ago, I managed things getting to work using a custom Dockerfile to install missing Linux packages for the XtraReports.
But today, I didn't want the overhead of creating a custom Dockerfile. I like a solution with plain Azure App Service for Linux, we only deploy a ZIP package that contains our code.

Our web application runs on .NET 8.0 using DevExpress XtraReports v23.2.4 - The `WebDocumentViewer` is used to display a report preview to the end user in the browser.

Following are the steps needed to get things working.

### Install these nuget packages 
- DevExpress.Drawing
- DevExpress.Drawing.Skia
- DevExpress.Reporting.Core
- Microsoft.ICU.ICU4C.Runtime

### Force the use of Skia rendering engine
This step is optional, see note below.
In Startup.cs force the use of the new Skia rendering engine 

```casharp
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
      DevExpress.Drawing.Internal.DXDrawingEngine.ForceSkia();
}
```

_DevExpress support note: The Skia engine automatically comes into use as long as you do not install libgdiplus._


### Add custom font to solution
Add your custom font the Visual Studio solution and make sure it has the "Copy always" output folder property set. I decided to put my fonts in a folder named `fonts`.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzmd5njbpua53c8jxnf8.png)

### Use a custom startup script for the App Service
Use a startup script for the App Service to install missing libraries. I decided to name the file `run.sh` and put it in my Visual Studio solution. The file should be set to "Copy Always" with no build process.

the contents of the file

```bash
#!/bin/bash
apt-get update &&
apt-get install -y libc6 libicu-dev libfontconfig1
cp fonts/FREE3OF9.TTF /usr/local/share/fonts
fc-cache -f -v
dotnet yourwebapp.dll
```

### Configure the App Service to execute the startup script
Set the App Service startup script to our `run.sh` in the portal
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uh4jx6ikje3zffmg4enp.png)

Helpful resources:
- https://supportcenter.devexpress.com/ticket/details/t1133108/reporting-for-asp-net-core-how-to-use-the-skiasharp-based-devexpress-drawing-engine
- https://docs.devexpress.com/CoreLibraries/404247/devexpress-drawing-library