View on GitHub

SARAFF SOFTWARE

All products / Saraff.TwainX.Extensions

Building and Publishing

Prerequisites

The library targets netstandard2.0; the test project targets net8.0.

Build

dotnet restore Saraff.TwainX.Extensions.sln
dotnet build Saraff.TwainX.Extensions.sln -c Release --no-restore

GeneratePackageOnBuild is enabled, so the build also produces the NuGet package in bin/Release/netstandard2.0.

Test

dotnet test Saraff.TwainX.Extensions.sln -c Release --no-build

The unit tests cover:

They do not require a scanner or a TWAIN DSM. Real acquisition is a hardware/integration test.

Pack

dotnet pack Saraff.TwainX.Extensions.csproj -c Release --no-build -o artifacts

The package contains:

Versioning

The version is stored in Saraff.TwainX.Extensions.csproj:

<Version>1.0.3.616</Version>
<AssemblyVersion>1.0.3.616</AssemblyVersion>
<FileVersion>1.0.3.616</FileVersion>

The publish workflow validates that the tag matches <Version>. For version 1.0.3.616 the tag is v1.0.3.616.

NuGet Trusted Publishing

The package is published with NuGet Trusted Publishing (OIDC), so no long-lived NuGet API key is stored. The workflow is .github/workflows/publish.yml.

nuget.org policy

Create a Trusted Publishing policy at https://www.nuget.org/account/trustedpublishing with these values (case-insensitive):

Field Value
Repository Owner saraff-9EB1047A4BEB4cef8506B29BA325BD5A
Repository Saraff.Twain.Extensions
Workflow File publish.yml
Environment nuget

Choose the account or organization that owns Saraff.TwainX.Extensions as the policy owner. Scope the policy to Saraff.TwainX.Extensions (for example, an exact package pattern or Saraff.Twain*). A policy scoped only to Saraff.Twain.Extensions does not authorize this package.

GitHub environment

Create an environment named nuget in the repository (Settings -> Environments -> New environment) and add a secret named NUGET_USER with the nuget.org profile name, not the email address. Optionally add required reviewers to gate releases.

The publish job requests id-token: write; the NuGet/login@v1 action exchanges the GitHub OIDC token for a temporary NuGet API key valid for one hour.

Triggering a publish

Push a tag that matches the project version:

git tag v1.0.3.616
git push origin v1.0.3.616

Or run Publish to NuGet manually from the Actions tab. workflow_dispatch is available only when the workflow file exists on the repository default branch.

The job runs restore, build, test, pack, OIDC login and dotnet nuget push for the packages in the artifacts directory. It publishes only Saraff.TwainX.Extensions; it does not touch the Saraff.Twain.Extensions package.

Publish checklist

  1. Bump <Version>, AssemblyVersion and FileVersion.
  2. Update the documentation and migration notes.
  3. Run dotnet test.
  4. Commit and push the changes.
  5. Create and push the matching tag.
  6. Confirm the workflow succeeded and the version appears on nuget.org.

CI

.github/workflows/ci.yml builds, tests and packs on Windows for pushes to master and pull requests. The publish workflow is separate and runs only for tags or manual dispatches.

Local package verification

Copy-Item bin/Release/*.nupkg "$env:TEMP\package.zip"
Expand-Archive "$env:TEMP\package.zip" "$env:TEMP\package" -Force
Get-Content "$env:TEMP\package\Saraff.TwainX.Extensions.nuspec"

Check the Saraff.TwainX dependency version, the readme, the license expression and the repository URL.