Files
Nemera/plugins/Nemera.Plugins.Pdf/Nemera.Plugins.Pdf.csproj

98 lines
7.8 KiB
XML

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\src\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
</ItemGroup>
<!-- The supported runtimes come from the shared bundled plugin runtime list. Each runtime also uses an OS family fallback folder, where the native dependency packages keep the libraries shared by every architecture of that operating system. -->
<Target Name="DefinePdfRuntimeLibraries">
<Error Condition="'@(BundledPluginRuntime)' == ''" Text="The bundled plugin runtime list is empty. Restore the BundledPluginRuntime items in build/RuntimeIdentifiers.props." />
<ItemGroup>
<_SupportedPdfRuntime Include="@(BundledPluginRuntime)" />
<_WindowsPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('win-'))">
<PdfFamily>win</PdfFamily>
</_WindowsPdfRuntime>
<_LinuxPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('linux-'))">
<PdfFamily>linux</PdfFamily>
</_LinuxPdfRuntime>
<_MacOsPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('osx-'))">
<PdfFamily>osx</PdfFamily>
</_MacOsPdfRuntime>
<_UnknownPdfRuntime Include="@(_SupportedPdfRuntime)" />
<_UnknownPdfRuntime Remove="@(_WindowsPdfRuntime);@(_LinuxPdfRuntime);@(_MacOsPdfRuntime)" />
<_PdfFamilyRuntime Include="win" Condition="'@(_WindowsPdfRuntime)' != ''" />
<_PdfFamilyRuntime Include="linux" Condition="'@(_LinuxPdfRuntime)' != ''" />
<_PdfFamilyRuntime Include="linux-musl" Condition="'@(_LinuxPdfRuntime)' != ''" />
<_PdfFamilyRuntime Include="osx" Condition="'@(_MacOsPdfRuntime)' != ''" />
</ItemGroup>
</Target>
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
<MakeDir Directories="$(_PluginsDestination)" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
<Copy SourceFiles="@(_PluginsReferenceCopyLocalPath)" DestinationFolder="$(_PluginsDestination)%(_PluginsReferenceCopyLocalPath.DestinationSubDirectory)" />
</Target>
<!-- Keeps the native runtime folders of every supported runtime and of its OS family fallback, and removes the flat native copies so the dependency manifest selects the right library for the host. The plugins folder is shared with the other bundled plugins, so only folders that contain the PDF native libraries are pruned. -->
<Target Name="PrunePdfNativeRuntimes" AfterTargets="Build" DependsOnTargets="DefinePdfRuntimeLibraries;SetPluginsDestination;CopyToPluginsFolder">
<ItemGroup>
<_CopiedRuntimeDirectory Include="$([System.IO.Directory]::GetDirectories('$(_PluginsDestination)runtimes'))" />
<_CopiedPdfRuntimeDirectory Include="@(_CopiedRuntimeDirectory)" Condition="Exists('%(Identity)/native/pdfium.dll') Or Exists('%(Identity)/native/libpdfium.so') Or Exists('%(Identity)/native/libpdfium.dylib') Or Exists('%(Identity)/native/libSkiaSharp.dll') Or Exists('%(Identity)/native/libSkiaSharp.so') Or Exists('%(Identity)/native/libSkiaSharp.dylib')" />
<_CopiedPdfRuntimeDirectory Remove="@(_SupportedPdfRuntime)" MatchOnMetadata="Filename" />
<_CopiedPdfRuntimeDirectory Remove="@(_PdfFamilyRuntime)" MatchOnMetadata="Filename" />
<_RootPdfNativeFile Include="$(_PluginsDestination)pdfium.dll;$(_PluginsDestination)libpdfium.so;$(_PluginsDestination)libpdfium.dylib;$(_PluginsDestination)libSkiaSharp.dll;$(_PluginsDestination)libSkiaSharp.so;$(_PluginsDestination)libSkiaSharp.dylib" />
</ItemGroup>
<RemoveDir Directories="@(_CopiedPdfRuntimeDirectory)" />
<Delete Files="@(_RootPdfNativeFile)" TreatErrorsAsWarnings="true" />
</Target>
<!-- The PDF plugin needs both native libraries for every supported runtime. A library satisfies the requirement when it is in the runtime's own folder or in its OS family fallback folder, which is how the macOS packages split SkiaSharp from pdfium. Deriving the list from the shared property makes adding a runtime without the matching package libraries fail the build. -->
<Target Name="ValidatePdfNativeLibraries" AfterTargets="Build" DependsOnTargets="PrunePdfNativeRuntimes">
<Error Condition="'@(_UnknownPdfRuntime)' != ''" Text="The bundled plugin runtime identifiers must be real runtime identifiers starting with win-, linux- or osx-, and must not list OS family fallback folders: @(_UnknownPdfRuntime)" />
<ItemGroup>
<_MissingPdfNativeLibrary Include="@(_WindowsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/pdfium.dll') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/pdfium.dll')">
<PdfNativeLibrary>pdfium.dll</PdfNativeLibrary>
</_MissingPdfNativeLibrary>
<_MissingPdfNativeLibrary Include="@(_WindowsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libSkiaSharp.dll') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libSkiaSharp.dll')">
<PdfNativeLibrary>libSkiaSharp.dll</PdfNativeLibrary>
</_MissingPdfNativeLibrary>
<_MissingPdfNativeLibrary Include="@(_LinuxPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libpdfium.so') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libpdfium.so')">
<PdfNativeLibrary>libpdfium.so</PdfNativeLibrary>
</_MissingPdfNativeLibrary>
<_MissingPdfNativeLibrary Include="@(_LinuxPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libSkiaSharp.so') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libSkiaSharp.so')">
<PdfNativeLibrary>libSkiaSharp.so</PdfNativeLibrary>
</_MissingPdfNativeLibrary>
<_MissingPdfNativeLibrary Include="@(_MacOsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libpdfium.dylib') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libpdfium.dylib')">
<PdfNativeLibrary>libpdfium.dylib</PdfNativeLibrary>
</_MissingPdfNativeLibrary>
<_MissingPdfNativeLibrary Include="@(_MacOsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libSkiaSharp.dylib') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libSkiaSharp.dylib')">
<PdfNativeLibrary>libSkiaSharp.dylib</PdfNativeLibrary>
</_MissingPdfNativeLibrary>
</ItemGroup>
<Error Condition="'@(_MissingPdfNativeLibrary)' != ''" Text="The PDF plugin is missing required native libraries (runtime: library): @(_MissingPdfNativeLibrary->'%(Identity): %(PdfNativeLibrary)')" />
</Target>
<ItemGroup>
<ProjectReference Include="..\..\src\Nemera.Plugins.Contracts\Nemera.Plugins.Contracts.csproj">
<Private>false</Private><!--Do not copy this assembly in the output directory, it's loaded from somewhere else.-->
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="PdfPig" />
<PackageReference Include="PDFtoImage" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>