【问题标题】:Azure Functions on Linux - Install Additional DependenciesLinux 上的 Azure Functions - 安装其他依赖项
【发布时间】:2021-12-28 05:13:11
【问题描述】:

使用 Linux 在 Premium Elastic Plan 上运行 C# Azure Functions 应用程序,利用一些有助于操作 MS Office 文件和 PDF 的 DevExpress 库,这些库显然依赖于 gdiplus,我似乎无法解决这个问题。

我们通过 Azure Portal for the Function App -> Configuration -> General settings -> Stack settings -> Startup Command 输入以下内容:

sudo apt-get update && sudo apt-get install -y 软件属性-common && sudo add-apt-repository 'deb http://deb.debian.org/debianbulseye main' && sudo apt-get update && sudo apt-get install -y libc6-dev && sudo apt-get install -y libgdiplus && sudo apt-get install -y libicu-dev && sudo apt-get install -y libharfbuzz0b && sudo apt-get install -y libfontconfig1 && sudo apt-get install -y libfreetype6 && sudo apt-get install -y libpango-1.0-0 && sudo apt-get install -y libpangocairo-1.0 && dotnet MyFunctionApp.dll

  • 用sudo和不用sudo都试过了,没区别,还是得到下面的异常
  • 尝试输入上面的内容,用双引号括起来并以 -c 为前缀以防万一(因为它被传递给 docker run 命令),没有区别

"Message":"发生错误。","ExceptionMessage":"类型 'DevExpress.Text.Fonts.GDIFontSubstitutionEngine' 的初始化程序 扔了一个 异常。","ExceptionType":"System.TypeInitializationException","StackTrace":" 在 DevExpress.Pdf.ContentGeneration.PdfExportFontManager.GetMatchingFont(PdfSetTextFontCommand setTextFontCommand)\n 在 DevExpress.Pdf.PdfInteractiveFormField.GetFontInfo(IPdfExportFontProvider 字体搜索)\n 在 DevExpress.Pdf.Native.PdfTextBasedFormFieldAppearanceBuilder`1..ctor(PdfWidgetAnnotation 小部件,T formField,IPdfExportFontProvider fontSearch,PdfRgbaColor 背景颜色)\n 在 DevExpress.Pdf.Native.PdfWidgetAppearanceBuilderFactory.DevExpress.Pdf.Native.IPdfInteractiveFormFieldVisitor.Visit(PdfTextFormField 表单域)\n 在 DevExpress.Pdf.PdfWidgetAnnotation.CreateAppearanceBuilder(IPdfExportFontProvider 字体搜索)\n 在 DevExpress.Pdf.PdfAnnotation.EnsureAppearance(PdfAnnotationAppearanceState 外观状态,PdfDocumentStateBase 文档状态,PdfForm 表单)\n
在 DevExpress.Pdf.PdfWidgetAnnotation.EnsureAppearance(PdfDocumentStateBase 文档状态)\n 在 DevExpress.Pdf.Native.PdfDocumentStateBase.CreateFormData(PdfInteractiveFormField 字段)\n 在 DevExpress.Pdf.Native.PdfDocumentStateBase.CreateFormData()\n

,"InnerException":{"Message":"出现错误 发生。","ExceptionMessage":"'Gdip' 的类型初始化程序抛出 一个 异常。","ExceptionType":"System.TypeInitializationException","StackTrace":" 在 System.Drawing.SafeNativeMethods.Gdip.GdipNewInstalledFontCollection(IntPtr& fontCollection)\n 在 DevExpress.Text.Fonts.GDIFontSubstitutionEngine.CreateFromGDIPlus()\n 在 DevExpress.Text.Fonts.GDIFontSubstitutionEngine..cctor()","InnerException":{"Message":"An 发生错误。","ExceptionMessage":"U无法加载共享库 'libgdiplus' 或其依赖项之一。 为了帮助诊断 加载问题,考虑设置 LD_DEBUG 环境变量: liblibgdiplus:无法打开共享对象文件:没有这样的文件或 目录","ExceptionType":"System.DllNotFoundException","StackTrace":" 在 System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& 令牌, StartupInput& 输入,StartupOutput& 输出)\n at System.Drawing.SafeNativeMethods.Gdip..cctor()"}}}

有什么想法吗?我也无法在这台机器上安装 WSL 进行本地调试。感谢任何提示。

【问题讨论】:

  • 您应该使用 Open XML SDK 来处理 Office 文件,并寻找与 .NET Core 兼容的 PDF 库/sdk。
  • 对不起@AnandSowmithiran 这是一个非常无知的评论;处理 Office 文件有很多不错的选择,我们正在使用的 DevExpress 当然是兼容 .Net Core 和跨平台的。问题是在 Linux 上,需要一个额外的依赖项,我无法在 Azure Functions 环境中安装它。 docs.devexpress.com/XtraReports/401730/web-reporting/…

标签: linux pdf azure-functions cross-platform gdi


【解决方案1】:

好吧,结果证明这很有趣。此后,启动命令输入已从 Azure 门户 UI 中的应用程序配置设置中删除,可能是因为它无法正常工作。实际上,完成此操作的唯一方法是使用自定义图像。

这是 docker 文件:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS installer-env

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish *.csproj --output /home/site/wwwroot -c Release


FROM mcr.microsoft.com/azure-functions/dotnet:3.0-appservice
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

RUN DEBIAN_FRONTEND=noninteractive apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated --no-install-recommends software-properties-common \
    && add-apt-repository "deb http://deb.debian.org/debian bullseye main" \
    && DEBIAN_FRONTEND=noninteractive apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y libc6 -f -o APT::Immediate-Configure=0 \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y \
        libgdiplus \
        libicu-dev \
        libharfbuzz0b \
        libfontconfig1 \
        libfreetype6 \
        libpango-1.0-0 \
        libpangocairo-1.0 \
    && rm -rf /var/lib/apt/lists/*

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 2014-11-06
    • 2022-01-22
    • 2016-08-21
    • 2023-03-12
    相关资源
    最近更新 更多