Skip to content

Commit

Permalink
Added support for .NET 8 (#1137)
Browse files Browse the repository at this point in the history
* Added support for .NET 8

- Updated test and sample projects to supports .NET 8
- Fixed compile warnings and errors including CS8352, CA1416
- Initial update to the tests workflow (runtests.yml)
- Removed previously deleted items from the solution file.

* Fixing workflow errors and warnings

- Added .NET 3.1
- Removed include-prerelease: false
- Upgraded actions/cache to v4 (from v1)

* Update runtests.yml

- Run tests in release mode (as the benchmark)
- Upgraded the actions/checkout (v2 to v4)

* Add test solutions to reduce unnecessary nuget package restore

- nuget restore is currently the longest running work on the workflow.
- initial attempt to improve it

* Removed CS0618 in debug mode, updated release notes.
  • Loading branch information
paulushub authored Feb 3, 2024
1 parent 030ac29 commit 02518c4
Show file tree
Hide file tree
Showing 31 changed files with 284 additions and 112 deletions.
42 changes: 23 additions & 19 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Testsuite

on:
[push, pull_request]
workflow_dispatch: # Allows manual triggering of workflow
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
test:
Expand All @@ -11,36 +15,37 @@ jobs:
matrix:
os: [windows-latest]
# os: [windows-latest, ubuntu-latest]
framework: [netcoreapp3.1, net6.0, net462]
framework: [net8.0, net6.0, netcoreapp3.1, net462]
steps:
- name: Checkout source
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed for GitVersioning to work
- name: Setup NuGet
uses: NuGet/setup-nuget@v1
- name: Cache NuGet packages
uses: actions/cache@v1
uses: actions/cache@v4
id: cache
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget }}
- name: Setup .NET 3.1 SDK
uses: actions/setup-dotnet@v3
- name: Setup .NET 3.1/8.0 SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 3.1.x
include-prerelease: false
dotnet-version: |
3.1.x
8.0.x
- name: Restore NuGet Packages
if: steps.cache.outputs.cache-hit != 'true'
run: |
nuget restore Source/Svg.sln
nuget install NUnit.ConsoleRunner -Version 3.10.0 -OutputDirectory tools
nuget restore Tests/Svg.UnitTests.sln
nuget install NUnit.ConsoleRunner -Version 3.17.0 -OutputDirectory tools
- name: Run tests
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
run: |
dotnet test --framework ${{ matrix.framework }} Tests/Svg.UnitTests/Svg.UnitTests.csproj
dotnet test -c Release -f ${{ matrix.framework }} Tests/Svg.UnitTests/Svg.UnitTests.csproj
benchmark:
runs-on: ${{ matrix.os }}
Expand All @@ -49,29 +54,28 @@ jobs:
benchmark: [SvgDocument, SvgPathBuilder, SvgTransformConverter, CoordinateParser]
os: [windows-latest]
# os: [windows-latest, ubuntu-latest]
framework: [netcoreapp3.1]
framework: [net8.0]
steps:
- name: Checkout source
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup NuGet
uses: NuGet/setup-nuget@v1
- name: Cache NuGet packages
uses: actions/cache@v1
uses: actions/cache@v4
id: cache
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-bench }}
- name: Setup .NET 3.1 SDK
uses: actions/setup-dotnet@v3
- name: Setup .NET 8.x SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 3.1.x
include-prerelease: false
dotnet-version: 8.0.x
- name: Restore NuGet Packages
if: steps.cache.outputs.cache-hit != 'true'
run: |
nuget restore Source/Svg.sln
nuget restore Tests/Svg.Benchmark.sln
- name: Run benchmarks
env:
DOTNET_NOLOGO: true
Expand Down
8 changes: 8 additions & 0 deletions Generators/Svg.Generators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<NoWarn>$(NoWarn);CS1591;CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Samples/Entities/Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>
Expand Down
3 changes: 3 additions & 0 deletions Samples/SVGBuilder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
#if NET5_0_OR_GREATER
[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
5 changes: 3 additions & 2 deletions Samples/SVGBuilder/SVGBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net6.0-windows;net462</TargetFrameworks>
<TargetFrameworks>net8.0-windows;net6.0-windows;net462</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>
Expand Down
3 changes: 3 additions & 0 deletions Samples/SVGViewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
#if NET5_0_OR_GREATER
[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
5 changes: 3 additions & 2 deletions Samples/SVGViewer/SVGViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net6.0-windows;net462</TargetFrameworks>
<TargetFrameworks>net8.0-windows;net6.0-windows;net462</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>
Expand Down
6 changes: 2 additions & 4 deletions Samples/SvgConsole/SvgConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
<PackAsTool>True</PackAsTool>
<ToolCommandName>SvgConsole</ToolCommandName>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<PropertyGroup>
<Configurations>Debug;Release</Configurations>
<PublishTrimmed>False</PublishTrimmed>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>
Expand Down
3 changes: 2 additions & 1 deletion Samples/SvgRuntimeUpdates/SvgRuntimeUpdates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion Source/DataTypes/SvgNumberCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static SvgNumberCollection Parse(ReadOnlySpan<char> numbers)
foreach (var part in parts)
{
var partValue = part.Value;
var result = StringParser.ToFloatAny(ref partValue);
var result = StringParser.ToFloatAny(partValue);
collection.Add(result);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/DataTypes/SvgPointCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
var coords = s.AsSpan().Trim();
var state = new CoordinateParserState(ref coords);
var result = new SvgPointCollection();
while (CoordinateParser.TryGetFloat(out var pointValue, ref coords, ref state))
while (CoordinateParser.TryGetFloat(out var pointValue, coords, ref state))
{
result.Add(new SvgUnit(SvgUnitType.User, pointValue));
}
Expand Down
4 changes: 2 additions & 2 deletions Source/DataTypes/SvgUnitConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using System.Globalization;
using Svg.Helpers;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static SvgUnit Parse(ReadOnlySpan<char> unit)
}

var valSpan = identifierIndex > -1 ? unit.Slice(0, identifierIndex) : unit;
var val = StringParser.ToFloat(ref valSpan);
var val = StringParser.ToFloat(valSpan);
if (identifierIndex == -1)
{
return new SvgUnit(val);
Expand Down
10 changes: 10 additions & 0 deletions Source/Exceptions/SvgException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace Svg
{
Expand All @@ -10,8 +12,10 @@ public SvgException() { }
public SvgException(string message) : base(message) { }
public SvgException(string message, Exception inner) : base(message, inner) { }

#if !NET8_0_OR_GREATER
protected SvgException(SerializationInfo info, StreamingContext context)
: base (info, context) { }
#endif
}

[Serializable]
Expand All @@ -21,8 +25,10 @@ public SvgIDException() { }
public SvgIDException(string message) : base(message) { }
public SvgIDException(string message, Exception inner) : base(message, inner) { }

#if !NET8_0_OR_GREATER
protected SvgIDException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
}

[Serializable]
Expand All @@ -32,8 +38,10 @@ public SvgIDExistsException() { }
public SvgIDExistsException(string message) : base(message) { }
public SvgIDExistsException(string message, Exception inner) : base(message, inner) { }

#if !NET8_0_OR_GREATER
protected SvgIDExistsException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
}

[Serializable]
Expand All @@ -43,7 +51,9 @@ public SvgIDWrongFormatException() { }
public SvgIDWrongFormatException(string message) : base(message) { }
public SvgIDWrongFormatException(string message, Exception inner) : base(message, inner) { }

#if !NET8_0_OR_GREATER
protected SvgIDWrongFormatException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
}
}
4 changes: 4 additions & 0 deletions Source/Exceptions/SvgGdiPlusCannotBeLoadedException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace Svg
{
Expand All @@ -13,7 +15,9 @@ public SvgGdiPlusCannotBeLoadedException(string message) : base(message) { }
public SvgGdiPlusCannotBeLoadedException(Exception inner) : base(gdiErrorMsg, inner) {}
public SvgGdiPlusCannotBeLoadedException(string message, Exception inner) : base(message, inner) { }

#if !NET8_0_OR_GREATER
protected SvgGdiPlusCannotBeLoadedException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
}
}
4 changes: 4 additions & 0 deletions Source/Exceptions/SvgMemoryException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace Svg.Exceptions
{
Expand All @@ -10,7 +12,9 @@ public SvgMemoryException() { }
public SvgMemoryException(string message) : base(message) { }
public SvgMemoryException(string message, Exception inner) : base(message, inner) { }

#if !NET8_0_OR_GREATER
protected SvgMemoryException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
}
}
8 changes: 4 additions & 4 deletions Source/Helpers/StringParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class StringParser
{
private static readonly CultureInfo Format = CultureInfo.InvariantCulture;

public static float ToFloat(ref ReadOnlySpan<char> value)
public static float ToFloat(ReadOnlySpan<char> value)
{
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
return float.Parse(value, NumberStyles.Float, Format);
Expand All @@ -16,7 +16,7 @@ public static float ToFloat(ref ReadOnlySpan<char> value)
#endif
}

public static float ToFloatAny(ref ReadOnlySpan<char> value)
public static float ToFloatAny(ReadOnlySpan<char> value)
{
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
return float.Parse(value, NumberStyles.Any, Format);
Expand All @@ -25,7 +25,7 @@ public static float ToFloatAny(ref ReadOnlySpan<char> value)
#endif
}

public static double ToDouble(ref ReadOnlySpan<char> value)
public static double ToDouble(ReadOnlySpan<char> value)
{
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
return double.Parse(value, NumberStyles.Any, Format);
Expand All @@ -34,7 +34,7 @@ public static double ToDouble(ref ReadOnlySpan<char> value)
#endif
}

public static int ToInt(ref ReadOnlySpan<char> value)
public static int ToInt(ReadOnlySpan<char> value)
{
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
return int.Parse(value, NumberStyles.Integer, Format);
Expand Down
8 changes: 4 additions & 4 deletions Source/Paths/CoordinateParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static bool MarkState(bool hasMode, ref CoordinateParserState state)
return hasMode;
}

public static bool TryGetBool(out bool result, ref ReadOnlySpan<char> chars, ref CoordinateParserState state)
public static bool TryGetBool(out bool result, ReadOnlySpan<char> chars, ref CoordinateParserState state)
{
var charsLength = chars.Length;

Expand Down Expand Up @@ -88,7 +88,7 @@ public static bool TryGetBool(out bool result, ref ReadOnlySpan<char> chars, ref
return MarkState(false, ref state);
}

public static bool TryGetFloat(out float result, ref ReadOnlySpan<char> chars, ref CoordinateParserState state)
public static bool TryGetFloat(out float result, ReadOnlySpan<char> chars, ref CoordinateParserState state)
{
var charsLength = chars.Length;

Expand Down Expand Up @@ -289,7 +289,7 @@ public static bool TryGetFloat(out float result, ref ReadOnlySpan<char> chars, r
if (state.CurrNumState != NumState.Separator && state.NewNumState < state.CurrNumState)
{
var value = chars.Slice(state.Position, state.CharsPosition - state.Position);
result = StringParser.ToFloat(ref value);
result = StringParser.ToFloat(value);
state.Position = state.CharsPosition;
state.CurrNumState = state.NewNumState;
return MarkState(true, ref state);
Expand All @@ -316,7 +316,7 @@ public static bool TryGetFloat(out float result, ref ReadOnlySpan<char> chars, r
else
{
var value = chars.Slice(state.Position, charsLength - state.Position);
result = StringParser.ToFloat(ref value);
result = StringParser.ToFloat(value);
state.Position = charsLength;
return MarkState(true, ref state);
}
Expand Down
Loading

0 comments on commit 02518c4

Please sign in to comment.