How to Build Aspose.OCR FOSS for .NET from Source
Aspose.OCR FOSS for .NET is open source: you can clone the repository and build it yourself at any time, independent of when the compiled package is published to a package registry. This guide walks through cloning, building, testing, and referencing the library from source using the .NET CLI.
Step-by-Step Guide
Step 1: Clone and Build
dotnet add package Aspose.OCR.FOSSBuilding all five target frameworks (netstandard2.0, net48, net8.0, net9.0,
net10.0) requires the .NET 10 SDK. To build a single target instead, use -f:
dotnet build src/Aspose.Ocr.Foss.csproj -c Release -f net8.0Step 2: Run the Test Suite
Run the full xUnit test project against the build you just produced:
dotnet test Aspose.Ocr.Foss.sln -c Release --no-buildTo run against one target framework only:
dotnet test tests/Aspose.Ocr.Foss.Tests.csproj -c Release -f net8.0Step 3: Reference the Library from Your Own Project
The simplest way to use a source build is a direct project reference from your own
.csproj:
<ItemGroup>
<ProjectReference Include="..\Aspose.OCR-FOSS-for-.NET\src\Aspose.Ocr.Foss.csproj" />
</ItemGroup>using Aspose.OCR;
var api = new AsposeOcr();
using var input = new OcrInput(InputType.SingleImage);
input.Add("scan.png");
Console.WriteLine(api.Recognize(input)[0].RecognitionText);Step 4: (Optional) Create a Package Artifact
build-packages.bat runs restore, build, test, and pack in one step and writes a .nupkg
to artifacts\packages:
build-packages.bat --no-pauseOr run the equivalent dotnet pack step directly, after a successful build:
dotnet pack src/Aspose.Ocr.Foss.csproj -c Release --no-build -o artifacts/packagesThis produces Aspose.OCR.FOSS.26.10.0.nupkg in artifacts/packages, a self-contained
package file you can copy or reference directly from other projects on the same machine.
Common Issues and Fixes
dotnet build fails with a missing-SDK error on one of the five target frameworks.
Building net9.0 and net10.0 targets requires the .NET 10 SDK. Build a single supported
target with -f net8.0 (or another installed target) if you only have an earlier SDK.
Tests fail or are skipped on a given target framework. The test project targets
net48, net8.0, net9.0, and net10.0. Run dotnet test tests/Aspose.Ocr.Foss.Tests.csproj -c Release -f net8.0
to isolate a single target.
dotnet pack reports the expected .nupkg was not created. Confirm the build and test
steps completed first — dotnet pack with --no-build requires a successful prior build.
Frequently Asked Questions
Do I need a published package to use this library?
No. A project reference to src/Aspose.Ocr.Foss.csproj works the same way a registry
package reference would, without waiting on any publication step.
Which .NET SDK do I need?
The .NET 10 SDK is required to build all five target frameworks
(netstandard2.0/net48/net8.0/net9.0/net10.0) from a single dotnet build call.
Earlier SDKs can still build a single supported target with -f.
What does build-packages.bat actually run?
Four steps in order: dotnet restore, dotnet build --configuration Release,
dotnet test --configuration Release --no-build, and dotnet pack --no-build producing
Aspose.OCR.FOSS.26.10.0.nupkg in artifacts/packages.