add .net8 support

This commit is contained in:
Jonas Dellinger 2024-02-10 11:56:20 +01:00
parent 78cc5a78da
commit 2bff224ef1
11 changed files with 50 additions and 7 deletions

View File

@ -18,7 +18,10 @@ jobs:
dotnet-version: "6.x"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.203"
dotnet-version: "7.x"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.x"
- name: Set RELEASE_VERSION
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Restore Packages
@ -54,12 +57,14 @@ jobs:
zip -j SpotifyAPI.Web-net5.0.zip SpotifyAPI.Web/bin/Release/net5.0/*
zip -j SpotifyAPI.Web-net6.0.zip SpotifyAPI.Web/bin/Release/net6.0/*
zip -j SpotifyAPI.Web-net7.0.zip SpotifyAPI.Web/bin/Release/net7.0/*
zip -j SpotifyAPI.Web-net8.0.zip SpotifyAPI.Web/bin/Release/net8.0/*
zip -j SpotifyAPI.Web.Auth-netstandard2.0.zip SpotifyAPI.Web.Auth/bin/Release/netstandard2.0/*
zip -j SpotifyAPI.Web.Auth-netstandard2.1.zip SpotifyAPI.Web.Auth/bin/Release/netstandard2.1/*
zip -j SpotifyAPI.Web.Auth-net5.0.zip SpotifyAPI.Web.Auth/bin/Release/net5.0/*
zip -j SpotifyAPI.Web.Auth-net6.0.zip SpotifyAPI.Web.Auth/bin/Release/net6.0/*
zip -j SpotifyAPI.Web.Auth-net7.0.zip SpotifyAPI.Web.Auth/bin/Release/net7.0/*
zip -j SpotifyAPI.Web.Auth-net8.0.zip SpotifyAPI.Web.Auth/bin/Release/net8.0/*
gh release upload "$RELEASE_VERSION" \
"SpotifyAPI.Web-netstandard2.0.zip" \
@ -67,10 +72,12 @@ jobs:
"SpotifyAPI.Web-net5.0.zip" \
"SpotifyAPI.Web-net6.0.zip" \
"SpotifyAPI.Web-net7.0.zip" \
"SpotifyAPI.Web-net8.0.zip" \
"SpotifyAPI.Web.Auth-netstandard2.0.zip" \
"SpotifyAPI.Web.Auth-netstandard2.1.zip" \
"SpotifyAPI.Web.Auth-net5.0.zip" \
"SpotifyAPI.Web.Auth-net6.0.zip" \
"SpotifyAPI.Web.Auth-net7.0.zip"
"SpotifyAPI.Web.Auth-net8.0.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<PackageId>SpotifyAPI.Web.Auth</PackageId>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
<CheckEolTargetFramework>false</CheckEolTargetFramework>

View File

@ -30,6 +30,9 @@ namespace SpotifyAPI.Web
{
}
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.")]
#endif
protected APIException(SerializationInfo info, StreamingContext context) : base(info, context)
{
Response = info.GetValue("APIException.Response", typeof(IResponse)) as IResponse;
@ -67,6 +70,11 @@ namespace SpotifyAPI.Web
return null;
}
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);

View File

@ -26,6 +26,9 @@ namespace SpotifyAPI.Web
public APIPagingException(string message, Exception innerException) : base(message, innerException) { }
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.")]
#endif
protected APIPagingException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@ -26,6 +26,9 @@ namespace SpotifyAPI.Web
public APITooManyRequestsException(string message, Exception innerException) : base(message, innerException) { }
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.")]
#endif
protected APITooManyRequestsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@ -15,6 +15,9 @@ namespace SpotifyAPI.Web
public APIUnauthorizedException(string message, Exception innerException) : base(message, innerException) { }
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.")]
#endif
protected APIUnauthorizedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}

View File

@ -166,7 +166,7 @@ namespace SpotifyAPI.Web.Http
_httpClient.SetRequestTimeout(timeout);
}
private IRequest CreateRequest(
private Request CreateRequest(
Uri uri,
HttpMethod method,
IDictionary<string, string>? parameters,

View File

@ -112,7 +112,7 @@ namespace SpotifyAPI.Web.Http
_httpClient.Timeout = timeout;
}
private static HttpMessageHandler CreateMessageHandler(IProxyConfig proxyConfig)
private static HttpClientHandler CreateMessageHandler(IProxyConfig proxyConfig)
{
var proxy = new WebProxy
{

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<PackageId>SpotifyAPI.Web</PackageId>

View File

@ -1,20 +1,31 @@
using System;
using System.Globalization;
using System.Text;
namespace SpotifyAPI.Web
{
internal class Base64Util
{
internal const string WebEncoders_InvalidCountOffsetOrLength = "Invalid {0}, {1} or {2} length.";
#if NET8_0_OR_GREATER
internal static CompositeFormat WebEncoders_MalformedInput = CompositeFormat.Parse("Malformed input: {0} is an invalid input length.");
#else
internal const string WebEncoders_MalformedInput = "Malformed input: {0} is an invalid input length.";
#endif
public static string UrlEncode(byte[] input)
{
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(input);
#else
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
#endif
// Special-case empty input
if (input.Length == 0)
@ -48,11 +59,15 @@ namespace SpotifyAPI.Web
public static byte[] UrlDecode(string input)
{
var buffer = new char[GetArraySizeRequiredToDecode(input.Length)];
#if NET8_0_OR_GREATER
ArgumentNullException.ThrowIfNull(input);
#else
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
#endif
var buffer = new char[GetArraySizeRequiredToDecode(input.Length)];
// Assumption: input is base64url encoded without padding and contains no whitespace.
@ -97,10 +112,14 @@ namespace SpotifyAPI.Web
private static int GetArraySizeRequiredToDecode(int count)
{
#if NET8_0_OR_GREATER
ArgumentOutOfRangeException.ThrowIfNegative(count);
#else
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}
#endif
if (count == 0)
{