When developing with LiteHTMLSharp using ProjectReference (rather than consuming published NuGet packages), you need to manually copy native libraries to your output directory.
Add this to your application's .csproj file:
<!-- Copy native libraries for local development -->
<ItemGroup>
<Content Include="path/to/LiteHTMLSharp/runtimes/**/*.dll;path/to/LiteHTMLSharp/runtimes/**/*.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes/%(RecursiveDir)%(Filename)%(Extension)</Link>
<TargetPath>runtimes/%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
</Content>
</ItemGroup>Replace path/to/LiteHTMLSharp with the actual path to your LiteHTMLSharp clone.
If your solution structure is:
MySolution/
LiteHTMLSharp/ (cloned repo)
runtimes/
osx-arm64/
osx-x64/
win-x64/
win-x86/
MyApp/
MyApp.csproj
Then in MyApp.csproj:
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)../LiteHTMLSharp/runtimes/**/*.dll;$(MSBuildThisFileDirectory)../LiteHTMLSharp/runtimes/**/*.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>runtimes/%(RecursiveDir)%(Filename)%(Extension)</Link>
<TargetPath>runtimes/%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
</Content>
</ItemGroup>For macOS app bundles (projects with <UseMacOSAppBundle>true</UseMacOSAppBundle>), use NativeReference instead of Content:
<ItemGroup>
<NativeReference Include="$(MSBuildThisFileDirectory)../runtimes/osx-arm64/native/liblitehtml.dylib" Condition="'$(RuntimeIdentifier)' == 'osx-arm64' OR '$(RuntimeIdentifier)' == ''">
<Kind>Dynamic</Kind>
<ForceLoad>False</ForceLoad>
</NativeReference>
<NativeReference Include="$(MSBuildThisFileDirectory)../runtimes/osx-x64/native/liblitehtml.dylib" Condition="'$(RuntimeIdentifier)' == 'osx-x64'">
<Kind>Dynamic</Kind>
<ForceLoad>False</ForceLoad>
</NativeReference>
</ItemGroup>This ensures native libraries are placed in the MonoBundle/ folder where .NET can find them in app bundles.
Native libraries need to be in specific locations for .NET's runtime to find them. When using published NuGet packages, this happens automatically. For local development with ProjectReference, you need to manually configure the copy.
If you want to test the NuGet packages locally before publishing, you can set up a local package source.
Windows:
mkdir %USERPROFILE%\LocalNuGet
dotnet nuget add source %USERPROFILE%\LocalNuGet --name LocalDevMac/Linux:
mkdir -p ~/LocalNuGet
dotnet nuget add source ~/LocalNuGet --name LocalDevAfter building the solution, copy all packages to your local source:
Windows:
copy /Y LiteHtmlSharp\bin\Debug\*.nupkg %USERPROFILE%\LocalNuGet\
copy /Y LiteHtmlSharp.Avalonia\bin\Debug\*.nupkg %USERPROFILE%\LocalNuGet\
copy /Y LiteHtmlSharp.Wpf\bin\Debug\*.nupkg %USERPROFILE%\LocalNuGet\
copy /Y LiteHtmlSharp.Mac\bin\Debug\*.nupkg %USERPROFILE%\LocalNuGet\
copy /Y LiteHtmlSharp.iOS\bin\Debug\*.nupkg %USERPROFILE%\LocalNuGet\Mac/Linux:
cp -f LiteHtmlSharp/bin/Debug/*.nupkg ~/LocalNuGet/
cp -f LiteHtmlSharp.Avalonia/bin/Debug/*.nupkg ~/LocalNuGet/
cp -f LiteHtmlSharp.Wpf/bin/Debug/*.nupkg ~/LocalNuGet/
cp -f LiteHtmlSharp.Mac/bin/Debug/*.nupkg ~/LocalNuGet/
cp -f LiteHtmlSharp.iOS/bin/Debug/*.nupkg ~/LocalNuGet/- Open Rider Settings/Preferences:
File → Settings(Windows) orRider → Preferences(Mac) - Navigate to:
Build, Execution, Deployment → NuGet → Sources - Your
LocalDevsource should appear with the path you configured - Make sure it's enabled (checkbox checked)
- Open NuGet Package Manager:
Tools → NuGet → Manage NuGet Packages for Solution - Select "LocalDev" from the source dropdown
- Browse and install your local packages
In your consuming project's .csproj:
<ItemGroup>
<PackageReference Include="LiteHtmlSharp.Avalonia" Version="2.0.2-preview4" />
</ItemGroup>Then restore:
dotnet restoreThe packages will be resolved from your LocalDev source.
If you rebuild packages and want to ensure the new versions are used:
Windows:
dotnet nuget locals all --clearMac/Linux:
dotnet nuget locals all --clearIf you're consuming published NuGet packages from NuGet.org, no additional setup is required - native libraries are included automatically.
<PackageReference Include="LiteHtmlSharp.Avalonia" Version="2.0.x" />Native libraries are stored in:
runtimes/
win-x64/native/LiteHtmlLib.dll
win-x86/native/LiteHtmlLib.dll
osx-x64/native/liblitehtml.dylib
osx-arm64/native/liblitehtml.dylib
.NET automatically searches these locations at runtime based on your platform's Runtime Identifier (RID).