Skip to content

Commit 02518c4

Browse files
authored
Added support for .NET 8 (#1137)
* 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.
1 parent 030ac29 commit 02518c4

31 files changed

+284
-112
lines changed

.github/workflows/runtests.yml

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: Testsuite
22

33
on:
4-
[push, pull_request]
4+
workflow_dispatch: # Allows manual triggering of workflow
5+
push:
6+
branches: [ "master" ]
7+
pull_request:
8+
branches: [ "master" ]
59

610
jobs:
711
test:
@@ -11,36 +15,37 @@ jobs:
1115
matrix:
1216
os: [windows-latest]
1317
# os: [windows-latest, ubuntu-latest]
14-
framework: [netcoreapp3.1, net6.0, net462]
18+
framework: [net8.0, net6.0, netcoreapp3.1, net462]
1519
steps:
1620
- name: Checkout source
17-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
1822
with:
1923
fetch-depth: 0 # needed for GitVersioning to work
2024
- name: Setup NuGet
2125
uses: NuGet/setup-nuget@v1
2226
- name: Cache NuGet packages
23-
uses: actions/cache@v1
27+
uses: actions/cache@v4
2428
id: cache
2529
with:
2630
path: ~/.nuget/packages
2731
key: ${{ runner.os }}-nuget }}
28-
- name: Setup .NET 3.1 SDK
29-
uses: actions/setup-dotnet@v3
32+
- name: Setup .NET 3.1/8.0 SDK
33+
uses: actions/setup-dotnet@v4
3034
with:
31-
dotnet-version: 3.1.x
32-
include-prerelease: false
35+
dotnet-version: |
36+
3.1.x
37+
8.0.x
3338
- name: Restore NuGet Packages
3439
if: steps.cache.outputs.cache-hit != 'true'
3540
run: |
36-
nuget restore Source/Svg.sln
37-
nuget install NUnit.ConsoleRunner -Version 3.10.0 -OutputDirectory tools
41+
nuget restore Tests/Svg.UnitTests.sln
42+
nuget install NUnit.ConsoleRunner -Version 3.17.0 -OutputDirectory tools
3843
- name: Run tests
3944
env:
4045
DOTNET_NOLOGO: true
4146
DOTNET_CLI_TELEMETRY_OPTOUT: true
4247
run: |
43-
dotnet test --framework ${{ matrix.framework }} Tests/Svg.UnitTests/Svg.UnitTests.csproj
48+
dotnet test -c Release -f ${{ matrix.framework }} Tests/Svg.UnitTests/Svg.UnitTests.csproj
4449
4550
benchmark:
4651
runs-on: ${{ matrix.os }}
@@ -49,29 +54,28 @@ jobs:
4954
benchmark: [SvgDocument, SvgPathBuilder, SvgTransformConverter, CoordinateParser]
5055
os: [windows-latest]
5156
# os: [windows-latest, ubuntu-latest]
52-
framework: [netcoreapp3.1]
57+
framework: [net8.0]
5358
steps:
5459
- name: Checkout source
55-
uses: actions/checkout@v2
60+
uses: actions/checkout@v4
5661
with:
5762
fetch-depth: 0
5863
- name: Setup NuGet
5964
uses: NuGet/setup-nuget@v1
6065
- name: Cache NuGet packages
61-
uses: actions/cache@v1
66+
uses: actions/cache@v4
6267
id: cache
6368
with:
6469
path: ~/.nuget/packages
6570
key: ${{ runner.os }}-nuget-bench }}
66-
- name: Setup .NET 3.1 SDK
67-
uses: actions/setup-dotnet@v3
71+
- name: Setup .NET 8.x SDK
72+
uses: actions/setup-dotnet@v4
6873
with:
69-
dotnet-version: 3.1.x
70-
include-prerelease: false
74+
dotnet-version: 8.0.x
7175
- name: Restore NuGet Packages
7276
if: steps.cache.outputs.cache-hit != 'true'
7377
run: |
74-
nuget restore Source/Svg.sln
78+
nuget restore Tests/Svg.Benchmark.sln
7579
- name: Run benchmarks
7680
env:
7781
DOTNET_NOLOGO: true

Generators/Svg.Generators.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
<Nullable>enable</Nullable>
99
<LangVersion>latest</LangVersion>
1010
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
11+
<Configurations>Debug;Release</Configurations>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
18+
<NoWarn>$(NoWarn);CS1591;CS0618</NoWarn>
1119
</PropertyGroup>
1220

1321
<ItemGroup>

Samples/Entities/Entities.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
6+
<Configurations>Debug;Release</Configurations>
67
</PropertyGroup>
78

89
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
9-
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
10+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
1011
</PropertyGroup>
1112
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1213
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>

Samples/SVGBuilder/Properties/AssemblyInfo.cs

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]
37+
#if NET5_0_OR_GREATER
38+
[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
39+
#endif

Samples/SVGBuilder/SVGBuilder.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFrameworks>net6.0-windows;net462</TargetFrameworks>
5+
<TargetFrameworks>net8.0-windows;net6.0-windows;net462</TargetFrameworks>
66
<UseWindowsForms>true</UseWindowsForms>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
9+
<Configurations>Debug;Release</Configurations>
910
</PropertyGroup>
1011

1112
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
12-
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
13+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
1314
</PropertyGroup>
1415
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1516
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>

Samples/SVGViewer/Properties/AssemblyInfo.cs

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]
37+
#if NET5_0_OR_GREATER
38+
[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
39+
#endif

Samples/SVGViewer/SVGViewer.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFrameworks>net6.0-windows;net462</TargetFrameworks>
5+
<TargetFrameworks>net8.0-windows;net6.0-windows;net462</TargetFrameworks>
66
<UseWindowsForms>true</UseWindowsForms>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
9+
<Configurations>Debug;Release</Configurations>
910
</PropertyGroup>
1011

1112
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
12-
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
13+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
1314
</PropertyGroup>
1415
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1516
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>

Samples/SvgConsole/SvgConsole.csproj

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
<PackAsTool>True</PackAsTool>
99
<ToolCommandName>SvgConsole</ToolCommandName>
1010
<LangVersion>7.3</LangVersion>
11-
</PropertyGroup>
12-
13-
<PropertyGroup>
11+
<Configurations>Debug;Release</Configurations>
1412
<PublishTrimmed>False</PublishTrimmed>
1513
<PublishReadyToRun>False</PublishReadyToRun>
1614
</PropertyGroup>
1715

1816
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
17+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
2018
</PropertyGroup>
2119
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2220
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>

Samples/SvgRuntimeUpdates/SvgRuntimeUpdates.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
6+
<Configurations>Debug;Release</Configurations>
67
</PropertyGroup>
78

89
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
9-
<NoWarn>$(NoWarn);CS0618;NETSDK1138</NoWarn>
10+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
1011
</PropertyGroup>
1112
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1213
<NoWarn>$(NoWarn);CS1591;CS0618;NETSDK1138</NoWarn>

Source/DataTypes/SvgNumberCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static SvgNumberCollection Parse(ReadOnlySpan<char> numbers)
6464
foreach (var part in parts)
6565
{
6666
var partValue = part.Value;
67-
var result = StringParser.ToFloatAny(ref partValue);
67+
var result = StringParser.ToFloatAny(partValue);
6868
collection.Add(result);
6969
}
7070

Source/DataTypes/SvgPointCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
6363
var coords = s.AsSpan().Trim();
6464
var state = new CoordinateParserState(ref coords);
6565
var result = new SvgPointCollection();
66-
while (CoordinateParser.TryGetFloat(out var pointValue, ref coords, ref state))
66+
while (CoordinateParser.TryGetFloat(out var pointValue, coords, ref state))
6767
{
6868
result.Add(new SvgUnit(SvgUnitType.User, pointValue));
6969
}

Source/DataTypes/SvgUnitConverter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.ComponentModel;
33
using System.Globalization;
44
using Svg.Helpers;
@@ -81,7 +81,7 @@ public static SvgUnit Parse(ReadOnlySpan<char> unit)
8181
}
8282

8383
var valSpan = identifierIndex > -1 ? unit.Slice(0, identifierIndex) : unit;
84-
var val = StringParser.ToFloat(ref valSpan);
84+
var val = StringParser.ToFloat(valSpan);
8585
if (identifierIndex == -1)
8686
{
8787
return new SvgUnit(val);

Source/Exceptions/SvgException.cs

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if !NET8_0_OR_GREATER
23
using System.Runtime.Serialization;
4+
#endif
35

46
namespace Svg
57
{
@@ -10,8 +12,10 @@ public SvgException() { }
1012
public SvgException(string message) : base(message) { }
1113
public SvgException(string message, Exception inner) : base(message, inner) { }
1214

15+
#if !NET8_0_OR_GREATER
1316
protected SvgException(SerializationInfo info, StreamingContext context)
1417
: base (info, context) { }
18+
#endif
1519
}
1620

1721
[Serializable]
@@ -21,8 +25,10 @@ public SvgIDException() { }
2125
public SvgIDException(string message) : base(message) { }
2226
public SvgIDException(string message, Exception inner) : base(message, inner) { }
2327

28+
#if !NET8_0_OR_GREATER
2429
protected SvgIDException(SerializationInfo info, StreamingContext context)
2530
: base(info, context) { }
31+
#endif
2632
}
2733

2834
[Serializable]
@@ -32,8 +38,10 @@ public SvgIDExistsException() { }
3238
public SvgIDExistsException(string message) : base(message) { }
3339
public SvgIDExistsException(string message, Exception inner) : base(message, inner) { }
3440

41+
#if !NET8_0_OR_GREATER
3542
protected SvgIDExistsException(SerializationInfo info, StreamingContext context)
3643
: base(info, context) { }
44+
#endif
3745
}
3846

3947
[Serializable]
@@ -43,7 +51,9 @@ public SvgIDWrongFormatException() { }
4351
public SvgIDWrongFormatException(string message) : base(message) { }
4452
public SvgIDWrongFormatException(string message, Exception inner) : base(message, inner) { }
4553

54+
#if !NET8_0_OR_GREATER
4655
protected SvgIDWrongFormatException(SerializationInfo info, StreamingContext context)
4756
: base(info, context) { }
57+
#endif
4858
}
4959
}

Source/Exceptions/SvgGdiPlusCannotBeLoadedException.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if !NET8_0_OR_GREATER
23
using System.Runtime.Serialization;
4+
#endif
35

46
namespace Svg
57
{
@@ -13,7 +15,9 @@ public SvgGdiPlusCannotBeLoadedException(string message) : base(message) { }
1315
public SvgGdiPlusCannotBeLoadedException(Exception inner) : base(gdiErrorMsg, inner) {}
1416
public SvgGdiPlusCannotBeLoadedException(string message, Exception inner) : base(message, inner) { }
1517

18+
#if !NET8_0_OR_GREATER
1619
protected SvgGdiPlusCannotBeLoadedException(SerializationInfo info, StreamingContext context)
1720
: base(info, context) { }
21+
#endif
1822
}
1923
}

Source/Exceptions/SvgMemoryException.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if !NET8_0_OR_GREATER
23
using System.Runtime.Serialization;
4+
#endif
35

46
namespace Svg.Exceptions
57
{
@@ -10,7 +12,9 @@ public SvgMemoryException() { }
1012
public SvgMemoryException(string message) : base(message) { }
1113
public SvgMemoryException(string message, Exception inner) : base(message, inner) { }
1214

15+
#if !NET8_0_OR_GREATER
1316
protected SvgMemoryException(SerializationInfo info, StreamingContext context)
1417
: base(info, context) { }
18+
#endif
1519
}
1620
}

Source/Helpers/StringParser.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static class StringParser
77
{
88
private static readonly CultureInfo Format = CultureInfo.InvariantCulture;
99

10-
public static float ToFloat(ref ReadOnlySpan<char> value)
10+
public static float ToFloat(ReadOnlySpan<char> value)
1111
{
1212
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
1313
return float.Parse(value, NumberStyles.Float, Format);
@@ -16,7 +16,7 @@ public static float ToFloat(ref ReadOnlySpan<char> value)
1616
#endif
1717
}
1818

19-
public static float ToFloatAny(ref ReadOnlySpan<char> value)
19+
public static float ToFloatAny(ReadOnlySpan<char> value)
2020
{
2121
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
2222
return float.Parse(value, NumberStyles.Any, Format);
@@ -25,7 +25,7 @@ public static float ToFloatAny(ref ReadOnlySpan<char> value)
2525
#endif
2626
}
2727

28-
public static double ToDouble(ref ReadOnlySpan<char> value)
28+
public static double ToDouble(ReadOnlySpan<char> value)
2929
{
3030
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
3131
return double.Parse(value, NumberStyles.Any, Format);
@@ -34,7 +34,7 @@ public static double ToDouble(ref ReadOnlySpan<char> value)
3434
#endif
3535
}
3636

37-
public static int ToInt(ref ReadOnlySpan<char> value)
37+
public static int ToInt(ReadOnlySpan<char> value)
3838
{
3939
#if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER
4040
return int.Parse(value, NumberStyles.Integer, Format);

Source/Paths/CoordinateParser.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static bool MarkState(bool hasMode, ref CoordinateParserState state)
4444
return hasMode;
4545
}
4646

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

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

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

@@ -289,7 +289,7 @@ public static bool TryGetFloat(out float result, ref ReadOnlySpan<char> chars, r
289289
if (state.CurrNumState != NumState.Separator && state.NewNumState < state.CurrNumState)
290290
{
291291
var value = chars.Slice(state.Position, state.CharsPosition - state.Position);
292-
result = StringParser.ToFloat(ref value);
292+
result = StringParser.ToFloat(value);
293293
state.Position = state.CharsPosition;
294294
state.CurrNumState = state.NewNumState;
295295
return MarkState(true, ref state);
@@ -316,7 +316,7 @@ public static bool TryGetFloat(out float result, ref ReadOnlySpan<char> chars, r
316316
else
317317
{
318318
var value = chars.Slice(state.Position, charsLength - state.Position);
319-
result = StringParser.ToFloat(ref value);
319+
result = StringParser.ToFloat(value);
320320
state.Position = charsLength;
321321
return MarkState(true, ref state);
322322
}

0 commit comments

Comments
 (0)