.net-coreselectpdf

Publish .NET app as a single file with .dep file included throws error as if its not included


The app uses Select.HtmlToPdf.NetCore NuGet package

When publishing the app, I've inputted

<DebugType>embedded</DebugType>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>True</IncludeNativeLibrariesForSelfExtract>

into .csproj to include all of the files into a single .exe (62,273 KB) file. While it does include all files and everything works up until a NuGet package code is being used. And throws an error Could not find 'Select.Html.dep' (trying to load Select.Html.dep).

By removing the IncludeNativeLibrariesForSelfExtract a Select.Html.dep (53,182 KB) is excluded from the .exe (10,092 KB) file and no error appears, the app works fine.

I'm guessing somehow in the code I need to tell where to find Select.Html.dep when it is included in the .exe. How would I do this? If not, what other options should I take?


Solution

  • By using IncludeNativeLibrariesForSelfExtract all of the additional content is extracted to

    %TEMP%\.net\<app>\<bundle-id>
    

    upon first launch of the app. Info: https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/extract.md

    With this information it is possible to find the missing .dep and update the path from which the program should load it like so:

    // Where tempDir is %TEMP%\.net\<app>\<bundle-id>
    GlobalProperties.HtmlEngineFullPath = tempDir + "\\Select.Html.dep";