Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CI/job_templates/deploy_drawing_libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,28 @@ jobs:
symbolServerType: TeamServices
detailedLog: true
# Store Version Information
- task: file-creator@6
# Built-in PowerShell instead of the marketplace file-creator@6 task, which runs on Node 10 and fails on
# current hosted agents ("No compatible Node.js version available for host execution").
- task: PowerShell@2
displayName: Store Version Information
inputs:
filepath: 'VersionInformation/versions.xml'
filecontent: |
targetType: 'inline'
pwsh: true
script: |
# Single-quoted: Azure DevOps substitutes the $(...) macros before the script runs; anything it
# leaves undefined is written literally, as the old task did, instead of being run by PowerShell.
$content = @'
<?xml version="1.0" encoding="utf-8"?>
<Versions>
<Configuration>$(Configuration)</Configuration>
<IronDrawingNuGetVersion>$(NuGetVersion)</IronDrawingNuGetVersion>
<IronDrawingAssemblyVersion>$(AssemblyVersion)</IronDrawingAssemblyVersion>
<GitCommitHash>$(Build.SourceVersion)</GitCommitHash>
</Versions>
fileoverwrite: true
verbose: true
'@
New-Item -ItemType Directory -Force -Path 'VersionInformation' | Out-Null
Set-Content -Path 'VersionInformation/versions.xml' -Value $content -Encoding utf8NoBOM
Get-Content 'VersionInformation/versions.xml'
- task: PublishBuildArtifacts@1
displayName: Publish IronDrawing Version Information
inputs:
Expand Down
29 changes: 21 additions & 8 deletions CI/scripts/Test-SystemAssemblyReferences.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,32 @@ function Get-AssemblyVersion([string] $path) {
finally { $stream.Dispose() }
}

# Lowest assembly version the given package version provides to .NET Framework / netstandard2.0
# consumers. The lib folders can differ (System.Memory 4.6.3: net462 = 4.0.5.0, netstandard2.0 = 4.0.2.0),
# so take the minimum to be safe for every consumer.
function Get-PackageAssemblyVersion([string] $id, [string] $version, [string] $assemblyName) {
# Assembly version the given package version provides to consumers of our $tfm lib folder.
# The package lib folders can differ (System.Memory 4.6.3: net462 = 4.0.5.0, netstandard2.0 = 4.0.2.0).
# - .NET Framework group: the app resolves the package's own .NET Framework lib folder (the highest
# net4x folder not above our target, else netstandard2.0), so check against that one.
# - netstandard2.0 group: it can be consumed from any .NET Framework or netstandard app, so take the
# minimum across those lib folders to be safe for every consumer.
function Get-PackageAssemblyVersion([string] $id, [string] $version, [string] $assemblyName, [string] $tfm) {
$packageDir = Join-Path $PackagesRoot (Join-Path $id.ToLowerInvariant() $version.ToLowerInvariant())
if (-not (Test-Path $packageDir)) {
# On a clean agent only the version the build restored is in the packages folder, so a declared
# version that is missing usually means the nuspec and the compile reference disagree.
return $null
}
$versions = foreach ($lib in 'net462', 'net461', 'net46', 'net45', 'netstandard2.0') {
$dll = Join-Path $packageDir "lib/$lib/$assemblyName.dll"
if (Test-Path $dll) { Get-AssemblyVersion $dll }
$candidates = 'net48', 'net472', 'net471', 'net47', 'net462', 'net461', 'net46', 'net45'
if ($tfm -match '^net4\d+$') {
$ours = [int]($tfm.Substring(3).PadRight(3, '0'))
$lib = @($candidates | Where-Object { [int]($_.Substring(3).PadRight(3, '0')) -le $ours }) + 'netstandard2.0' |
Where-Object { Test-Path (Join-Path $packageDir "lib/$_/$assemblyName.dll") } |
Select-Object -First 1
$versions = if ($lib) { Get-AssemblyVersion (Join-Path $packageDir "lib/$lib/$assemblyName.dll") }
}
else {
$versions = foreach ($lib in $candidates + 'netstandard2.0') {
$dll = Join-Path $packageDir "lib/$lib/$assemblyName.dll"
if (Test-Path $dll) { Get-AssemblyVersion $dll }
}
}
if (-not $versions) {
throw "No .NET Framework / netstandard2.0 assembly found for $id $version in '$packageDir'."
Expand Down Expand Up @@ -132,7 +145,7 @@ foreach ($group in $nuspec.SelectNodes("//*[local-name()='dependencies']/*[local
continue
}
$packageVersion = $declared[$ref.Name]
$provided = Get-PackageAssemblyVersion $ref.Name $packageVersion $ref.Name
$provided = Get-PackageAssemblyVersion $ref.Name $packageVersion $ref.Name $tfm
if ($null -eq $provided) {
$failures.Add("[$tfm] The nuspec declares $($ref.Name) $packageVersion, but that version is not restored in '$PackagesRoot'. $($dll.Name) was probably compiled against a different version: check IronSoftware.Drawing/SystemPackages.props against the nuspec.")
continue
Expand Down
9 changes: 9 additions & 0 deletions CI/stage_templates/run_tests_on_pool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ stages:
framework: 'net48'
architecture: ''
buildConfiguration: $(Configuration)
# Windows .NET 481 x64 Tests: net481 loads the netstandard2.0 build (ImageSharp 2.1.13 + BigTIFF guard),
# while net48 loads the net462 (SkiaSharp) build. See IronSoftware.Drawing.Common.Tests.csproj.
- template: ../job_templates/test_drawing_libraries.yml
parameters:
name: UnitTest${{ parameters.OSPlatform }}net481x64
OSPlatform: ${{ parameters.OSPlatform }}
framework: 'net481'
architecture: ''
buildConfiguration: $(Configuration)
# .NET 8.0 Tests
- template: ../job_templates/test_drawing_libraries.yml
parameters:
Expand Down
17 changes: 17 additions & 0 deletions CI/step_templates/sign_drawing_libraries_dll.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ steps:
--file-digest sha256 `
--verbose `
"IronSoftware.Drawing.Common.dll"
- task: PowerShell@2
displayName: 'Sign IronSoftware.Drawing.Common.dll .NET Framework (net462)'
inputs:
workingDirectory: 'bin\$(Configuration)\net462'
targetType: 'inline'
script: |
azuresigntool sign `
--azure-key-vault-url "$(AZURE_KEY_VAULT_URL)" `
--azure-key-vault-client-id "$(AZURE_KEY_VAULT_APPLICATION_ID)" `
--azure-key-vault-client-secret "$(AZURE_KEY_VAULT_CLIENT_SECRET)" `
--azure-key-vault-tenant-id "$(AZURE_KEY_VAULT_TENANT_ID)" `
--azure-key-vault-certificate "$(AZURE_KEY_VAULT_CERTIFICATE_NAME)" `
--timestamp-rfc3161 "$(TimestampUrl)" `
--timestamp-digest sha256 `
--file-digest sha256 `
--verbose `
"IronSoftware.Drawing.Common.dll"
- task: PowerShell@2
displayName: 'Sign IronSoftware.Drawing.Common.dll .NET 6 (net60)'
inputs:
Expand Down
17 changes: 17 additions & 0 deletions IronSoftware.Drawing/DependencyVersions.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<!--
Versions of the packages IronSoftware.Drawing.Common's netstandard2.0 build depends on (plus the ones shared
with other targets). Imported by IronSoftware.Drawing.Common.csproj and by the test project, whose net481
target references the netstandard2.0 build directly and must restore exactly the same dependency set.
Keep the netstandard2.0 group of NuGet/IronSoftware.Drawing.nuspec in sync.
-->
<PropertyGroup>
<DrawingAbstractionsVersion>2026.1.2</DrawingAbstractionsVersion>
<LibTiffVersion>2.4.649</LibTiffVersion>
<NetStandardImageSharpVersion>2.1.13</NetStandardImageSharpVersion>
<NetStandardImageSharpDrawingVersion>1.0.0</NetStandardImageSharpDrawingVersion>
<!-- SkiaSharp line used by the netstandard2.0, net6.0 and net8.0 builds (net462 uses SkiaSharp 4). -->
<LegacySkiaSharpVersion>2.88.7</LegacySkiaSharpVersion>
<SkiaSharpSvgVersion>1.60.0</SkiaSharpSvgVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;net80</TargetFrameworks>
<TargetFrameworks>net48;net481;net80</TargetFrameworks>
<LangVersion>latest</LangVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IsPackable>false</IsPackable>
Expand All @@ -14,8 +14,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.Maui.Graphics" Version="7.0.92" />
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="6.0.5.128" />
<PackageReference Include="SkiaSharp" Version="2.88.7" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand All @@ -28,8 +26,52 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
Comment thread
Sawraz-IS marked this conversation as resolved.
Resolved
<!-- IronSoftware.Drawing.Common net462 runs on SkiaSharp 4.x; ImageSharp is referenced here only by the test helpers (Compare.cs). -->
<PackageReference Include="SkiaSharp" Version="4.153.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.13" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net48'">
<PackageReference Include="SkiaSharp" Version="$(LegacySkiaSharpVersion)" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="$(LegacySkiaSharpVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net481'">
<ProjectReference Include="..\IronSoftware.Drawing.Common\IronSoftware.Drawing.Common.csproj" />
</ItemGroup>

<!--
net481 tests Drawing's netstandard2.0 build (ImageSharp 2.1.13 and the BigTIFF guard), which still ships to
netstandard2.0 consumers; net48 picks the net462 build. A normal ProjectReference would resolve net462 for
net481 too, so reference the netstandard2.0 output directly (built first through the reference below,
which ReferenceOutputAssembly=false keeps out of restore) and declare its dependencies. The versions come
from the same DependencyVersions.props and SystemPackages.props that the Drawing csproj uses.
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<ProjectReference Include="..\IronSoftware.Drawing.Common\IronSoftware.Drawing.Common.csproj" SetTargetFramework="TargetFramework=netstandard2.0" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
<Reference Include="IronSoftware.Drawing.Common">
<HintPath>..\IronSoftware.Drawing.Common\bin\$(Configuration)\netstandard2.0\IronSoftware.Drawing.Common.dll</HintPath>
</Reference>
<PackageReference Include="IronSoftware.Drawing.Abstractions" Version="$(DrawingAbstractionsVersion)" />
<PackageReference Include="BitMiracle.LibTiff.NET" Version="$(LibTiffVersion)" />
<PackageReference Include="SixLabors.ImageSharp" Version="$(NetStandardImageSharpVersion)" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="$(NetStandardImageSharpDrawingVersion)" />
<PackageReference Include="SkiaSharp.Svg" Version="$(SkiaSharpSvgVersion)" />
</ItemGroup>

<!-- Version properties shared with the Drawing csproj (SystemPackages.props' own package items only target the library's TFMs). -->
<Import Project="..\SystemPackages.props" />
<Import Project="..\DependencyVersions.props" />

<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Numerics.Vectors" Version="$(SystemNumericsVectorsVersion)" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafeVersion)" />
</ItemGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public void AnyBitmap_should_get_Bytes()
Assert.Equal(expected, resultExport);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void AnyBitmap_should_set_Pixel()
{
Expand Down Expand Up @@ -290,6 +291,7 @@ public void AnyBitmap_should_set_Pixel()
#endif
}
}
#endif

[FactWithAutomaticDisplayName]
public void AnyBitmap_should_get_Stream()
Expand Down Expand Up @@ -339,6 +341,7 @@ public void AnyBitmap_should_ToString()
Assert.Equal(expected, result);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void AnyBitmap_GetPixel_should_not_throw_OutOfMemoryException()
{
Expand Down Expand Up @@ -390,6 +393,7 @@ public void Clone_AnyBitmap()

AssertImageAreEqual("expected.png", "result.png", true);
}
#endif

[FactWithAutomaticDisplayName]
public void Clone_Crop_AnyBitmap()
Expand Down Expand Up @@ -473,6 +477,7 @@ public void CastSKImage_from_AnyBitmap()
AssertImageAreEqual("expected.png", "result.png", true);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CastSixLabors_to_AnyBitmap()
{
Expand Down Expand Up @@ -533,6 +538,7 @@ public void CastSixLabors_from_AnyBitmap_Rgba32(string filename)

AssertImageAreEqual("expected.bmp", "result.bmp", true);
}
#endif

[FactWithAutomaticDisplayName]
public void CastBitmap_to_AnyBitmap_using_FromBitmap()
Expand Down Expand Up @@ -711,6 +717,7 @@ public void Create_Multi_page_Tiff_Paths()
File.Delete(outputImagePath);
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiffStream_Preserves_Mixed_Orientation()
{
Expand Down Expand Up @@ -753,6 +760,7 @@ public void CreateMultiFrameTiffBytes_Preserves_Per_Page_Dimensions_And_Resoluti
.Should().BeApproximately(150d, 2d);
}
}
#endif

[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiffStream_Empty_Sequence_Throws()
Expand All @@ -761,6 +769,7 @@ public void CreateMultiFrameTiffStream_Empty_Sequence_Throws()
act.Should().Throw<ArgumentException>();
}

#if !NET48
[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiffBytes_PreservesResolution_FromPixelsPerMeterSource()
{
Expand All @@ -777,12 +786,18 @@ public void CreateMultiFrameTiffBytes_PreservesResolution_FromPixelsPerMeterSour
ToDotsPerInch(pages[0].XResolution, pages[0].ResolutionUnit)
.Should().BeApproximately(dpi, 2d);
}
#endif

[FactWithAutomaticDisplayName]
public void CreateMultiFrameTiff_Preserves_Rgb24_Pixels()
{
string jpgPath = GetRelativeFilePath("mountainclimbers.jpg");
#if NET48
// JPEG decoders differ by a few levels; compare against the same engine's decode of the source.
using var expected = AnyBitmap.FromFile(jpgPath);
#else
using var expected = SixLabors.ImageSharp.Image.Load<Rgb24>(jpgPath);
#endif

using var result = AnyBitmap.CreateMultiFrameTiff(new List<string> { jpgPath });

Expand All @@ -801,14 +816,19 @@ public void CreateMultiFrameTiff_Preserves_Rgb24_Pixels()

foreach (var (x, y) in points)
{
#if NET48
var e = expected.GetPixel(x, y);
#else
Rgb24 e = expected[x, y];
#endif
var a = result.GetPixel(x, y);
a.R.Should().Be(e.R, $"red channel at ({x},{y})");
a.G.Should().Be(e.G, $"green channel at ({x},{y})");
a.B.Should().Be(e.B, $"blue channel at ({x},{y})");
}
}

#if !NET48
[TheoryWithAutomaticDisplayName]
[InlineData("Rgb24")]
[InlineData("Bgr24")]
Expand Down Expand Up @@ -873,6 +893,7 @@ private static AnyBitmap MakeBitmapWithResolution(int width, int height, Rgb24 c
image.Metadata.ResolutionUnits = unit;
return image;
}
#endif

private static List<(int Width, int Height, float XResolution, ResUnit ResolutionUnit)> ReadTiffDirectories(byte[] tiffData)
{
Expand Down Expand Up @@ -913,6 +934,7 @@ private static double ToDotsPerInch(float xResolution, ResUnit unit)
};
}

#if !NET48
[FactWithAutomaticDisplayName]
public void Create_Multi_page_Gif()
{
Expand Down Expand Up @@ -988,6 +1010,7 @@ public void Should_Return_BitsPerPixel()
bitmap = Image.Load<Rgba32>(GetRelativeFilePath("mountainclimbers.jpg"));
Assert.Equal(32, bitmap.BitsPerPixel);
}
#endif

[TheoryWithAutomaticDisplayName]
[InlineData("ScanDev_BW.tif", 1)]
Expand Down Expand Up @@ -1173,6 +1196,7 @@ public void Resize_ShouldPreserveDepthForRepresentableFormats()
}
}

#if !NET48
[TheoryWithAutomaticDisplayName]
[InlineData("A8", "GrayscaleWithAlpha", "Bit8", 16)]
[InlineData("L8", "Grayscale", "Bit8", 8)]
Expand Down Expand Up @@ -1219,6 +1243,7 @@ public void ExportPng_ShouldChooseColorTypeAndBitDepthFromPixelType(
}
Assert.Equal(expectedBitsPerPixel, AnyBitmap.FromBytes(png).BitsPerPixel);
}
#endif

[TheoryWithAutomaticDisplayName]
[InlineData("Palette", "Bit8")]
Expand Down Expand Up @@ -1369,6 +1394,7 @@ public void Should_RotateFlip()
AssertImageAreEqual(GetRelativeFilePath("checkmarkFlip.jpg"), "result_flip.bmp");
}

#if !NET48
[FactWithAutomaticDisplayName]
public void Redact_ShouldRedactRegionWithColor()
{
Expand Down Expand Up @@ -1409,6 +1435,7 @@ public void Redact_ShouldRedactRegionWithColor()
}
}
}
#endif

[FactWithAutomaticDisplayName]
public void TestGetRGBBuffer()
Expand Down Expand Up @@ -1654,6 +1681,7 @@ public void LoadImage_SetPreserveOriginalFormat_ShouldReturnCorrectBitPerPixel(s
}

#if !NET7_0
#if !NET48
[FactWithAutomaticDisplayName]
public void CastAnyBitmap_from_SixLabors()
{
Expand All @@ -1669,6 +1697,7 @@ public void CastAnyBitmap_from_SixLabors()
AssertLargeImageAreEqual("expected.bmp", "result.bmp", true);
}
#endif
#endif


[IgnoreOnAzureDevopsX86Fact]
Expand Down
Loading