diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 7f1b37ce..94631cd8 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -10,6 +10,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: "4.8.1" - uses: actions/setup-dotnet@v1 with: dotnet-version: "5.x" @@ -49,21 +52,25 @@ jobs: - name: Upload to GH Release if: startsWith( github.ref, 'refs/tags/') run: | + zip -j SpotifyAPI.Web-netstandard2.0.zip SpotifyAPI.Web/bin/Release/netstandard2.0/* zip -j SpotifyAPI.Web-netstandard2.1.zip SpotifyAPI.Web/bin/Release/netstandard2.1/* 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.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/* hub release edit \ + -a "SpotifyAPI.Web-netstandard2.0.zip" \ -a "SpotifyAPI.Web-netstandard2.1.zip" \ -a "SpotifyAPI.Web-net5.0.zip" \ -a "SpotifyAPI.Web-net6.0.zip" \ -a "SpotifyAPI.Web-net7.0.zip" \ + -a "SpotifyAPI.Web.Auth-netstandard2.0.zip" \ -a "SpotifyAPI.Web.Auth-netstandard2.1.zip" \ -a "SpotifyAPI.Web.Auth-net5.0.zip" \ -a "SpotifyAPI.Web.Auth-net6.0.zip" \ diff --git a/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj b/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj index e1a64c86..1ce9f5be 100644 --- a/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj +++ b/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0;netstandard2.1 + net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0 9.0 enable SpotifyAPI.Web.Auth diff --git a/SpotifyAPI.Web/Clients/Interfaces/IPaginator.cs b/SpotifyAPI.Web/Clients/Interfaces/IPaginator.cs index 007343e7..1bb8db16 100644 --- a/SpotifyAPI.Web/Clients/Interfaces/IPaginator.cs +++ b/SpotifyAPI.Web/Clients/Interfaces/IPaginator.cs @@ -42,6 +42,7 @@ namespace SpotifyAPI.Web CancellationToken cancel = default ); +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER /// /// Fetches all pages and returns one by one using IAsyncEnumerable /// @@ -71,5 +72,6 @@ namespace SpotifyAPI.Web IAPIConnector connector, CancellationToken cancel = default ); +#endif } } diff --git a/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs b/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs index 29b78400..6fcbfc47 100644 --- a/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs +++ b/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs @@ -131,6 +131,7 @@ namespace SpotifyAPI.Web CancellationToken cancellationToken = default! ); +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER /// /// Paginate through pages by using IAsyncEnumerable, introduced in C# 8 /// The default paginator will fetch all available resources without a delay between requests. @@ -167,6 +168,7 @@ namespace SpotifyAPI.Web IPaginator? paginator = default!, CancellationToken cancel = default! ); +#endif public Task> NextPage(Paging paging); diff --git a/SpotifyAPI.Web/Clients/SimplePaginator.cs b/SpotifyAPI.Web/Clients/SimplePaginator.cs index 6defa01d..4c7fe968 100644 --- a/SpotifyAPI.Web/Clients/SimplePaginator.cs +++ b/SpotifyAPI.Web/Clients/SimplePaginator.cs @@ -69,6 +69,7 @@ namespace SpotifyAPI.Web return results; } +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER public async IAsyncEnumerable Paginate( IPaginatable firstPage, IAPIConnector connector, @@ -125,5 +126,6 @@ namespace SpotifyAPI.Web } } } +#endif } } diff --git a/SpotifyAPI.Web/Clients/SpotifyClient.cs b/SpotifyAPI.Web/Clients/SpotifyClient.cs index 24fdfe3f..25ad10f7 100644 --- a/SpotifyAPI.Web/Clients/SpotifyClient.cs +++ b/SpotifyAPI.Web/Clients/SpotifyClient.cs @@ -196,7 +196,7 @@ namespace SpotifyAPI.Web return FetchPage(paging.Previous); } - +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER /// /// Paginate through pages by using IAsyncEnumerable, introduced in C# 8 /// The default paginator will fetch all available resources without a delay between requests. @@ -303,5 +303,6 @@ namespace SpotifyAPI.Web yield return item; } } +#endif } } diff --git a/SpotifyAPI.Web/Http/APIConnector.cs b/SpotifyAPI.Web/Http/APIConnector.cs index 43fd6dd2..4904fa27 100644 --- a/SpotifyAPI.Web/Http/APIConnector.cs +++ b/SpotifyAPI.Web/Http/APIConnector.cs @@ -221,7 +221,11 @@ namespace SpotifyAPI.Web.Http { if (_authenticator != null && !request.Endpoint.IsAbsoluteUri +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER || request.Endpoint.AbsoluteUri.Contains("https://api.spotify.com", StringComparison.InvariantCulture)) +#else + || request.Endpoint.AbsoluteUri.Contains("https://api.spotify.com")) +#endif { await _authenticator!.Apply(request, this).ConfigureAwait(false); } diff --git a/SpotifyAPI.Web/Http/NetHttpClient.cs b/SpotifyAPI.Web/Http/NetHttpClient.cs index 1730ea55..07cbf350 100644 --- a/SpotifyAPI.Web/Http/NetHttpClient.cs +++ b/SpotifyAPI.Web/Http/NetHttpClient.cs @@ -50,10 +50,10 @@ namespace SpotifyAPI.Web.Http // We only support text stuff for now using var content = responseMsg.Content; var headers = responseMsg.Headers.ToDictionary(header => header.Key, header => header.Value.First()); -#if NETSTANDARD2_1 - var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false); -#else +#if NET5_0_OR_GREATER var body = await responseMsg.Content.ReadAsStringAsync(cancel).ConfigureAwait(false); +#else + var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false); #endif var contentType = content.Headers?.ContentType?.MediaType; diff --git a/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs b/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs index 5732b543..acd5f4a3 100644 --- a/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs +++ b/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs @@ -7,7 +7,6 @@ namespace SpotifyAPI.Web.Http { private const string OnRequestFormat = "\n{0} {1} [{2}] {3}"; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")] public void OnRequest(IRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); @@ -23,12 +22,14 @@ namespace SpotifyAPI.Web.Http Console.WriteLine(OnRequestFormat, request.Method, request.Endpoint, parameters, request.Body); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")] public void OnResponse(IResponse response) { Ensure.ArgumentNotNull(response, nameof(response)); +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER string? body = response.Body?.ToString()?.Replace("\n", "", StringComparison.InvariantCulture); - +#else + string? body = response.Body?.ToString()?.Replace("\n", ""); +#endif body = body?.Substring(0, Math.Min(50, body.Length)); Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body); } diff --git a/SpotifyAPI.Web/SpotifyAPI.Web.csproj b/SpotifyAPI.Web/SpotifyAPI.Web.csproj index 4bfc6c94..e1ebc477 100644 --- a/SpotifyAPI.Web/SpotifyAPI.Web.csproj +++ b/SpotifyAPI.Web/SpotifyAPI.Web.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0;net5.0;netstandard2.1 + net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0 9.0 enable SpotifyAPI.Web diff --git a/SpotifyAPI.Web/Util/PKCEUtil.cs b/SpotifyAPI.Web/Util/PKCEUtil.cs index 8611ce2c..6c8faf25 100644 --- a/SpotifyAPI.Web/Util/PKCEUtil.cs +++ b/SpotifyAPI.Web/Util/PKCEUtil.cs @@ -63,11 +63,11 @@ namespace SpotifyAPI.Web private static byte[] ComputeSHA256(string value) { -#if NETSTANDARD2_1_OR_GREATER +#if NET5_0_OR_GREATER + return SHA256.HashData(Encoding.UTF8.GetBytes(value)); +#else using var hash = SHA256.Create(); return hash.ComputeHash(Encoding.UTF8.GetBytes(value)); -#else - return SHA256.HashData(Encoding.UTF8.GetBytes(value)); #endif } } diff --git a/SpotifyAPI.Web/Util/StringAttribute.cs b/SpotifyAPI.Web/Util/StringAttribute.cs index aa53556d..e63bf0f5 100644 --- a/SpotifyAPI.Web/Util/StringAttribute.cs +++ b/SpotifyAPI.Web/Util/StringAttribute.cs @@ -15,7 +15,11 @@ namespace SpotifyAPI.Web public string Value { get; } +#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER public static bool GetValue(Type enumType, Enum enumValue, [NotNullWhen(true)] out string? result) +#else + public static bool GetValue(Type enumType, Enum enumValue, out string? result) +#endif { Ensure.ArgumentNotNull(enumType, nameof(enumType)); Ensure.ArgumentNotNull(enumValue, nameof(enumValue));