Skip to content

Commit

Permalink
Update for NET6/7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
seamasmcgettrick authored Sep 15, 2023
1 parent 9bc6084 commit b7e00df
Show file tree
Hide file tree
Showing 26 changed files with 227 additions and 53 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
name: Deploy

on:
workflow_dispatch:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

dotnet-version: |
3.1.x
6.0.x
7.0.x
- name: Retore Workload
run: dotnet workload restore
- name: Restore dependencies
run: dotnet restore
- name: Set Assembly Version
run: ./build.sh --task=GitVersion --configuration=Release
- name: Build Library
run: dotnet build ./Float.Core/Float.Core.csproj --configuration Release --no-restore
- name: Update Version
run: sed -i "s/<Version><\/Version>/<Version>${{ github.event.release.name }}<\/Version>/" ./Float.Core/Float.Core.csproj
- name: Pack and Upload
run: dotnet pack --configuration Release --no-restore
- name: Deploy to NuGet
env:
FLOAT_NUGET_TOKEN: ${{ secrets.FLOAT_NUGET_TOKEN }}
run: ./build.sh --task=Deploy --configuration=Release --nugetUrl="https://api.nuget.org/v3/index.json" --nugetToken="${FLOAT_NUGET_TOKEN}"
run: dotnet nuget push ./Float.Core/bin/Release/Float.Core.${{ github.event.release.name }}.nupkg --api-key "${FLOAT_NUGET_TOKEN}" --source https://api.nuget.org/v3/index.json
36 changes: 23 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@ name: Test

on:
pull_request:
branches: [ main ]
branches: [main]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
3.1.x
6.0.x
7.0.x
- name: Retore Workload
run: dotnet workload restore
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal --logger:"trx;"
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
**/TestResults/*.trx
5 changes: 5 additions & 0 deletions Float.Core.Tests/DebounceCommand.tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System.Threading;
using System.Threading.Tasks;
using Float.Core.Commands;
#if NETCOREAPP3_1
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif
using Xunit;

namespace Float.Core.Tests
Expand Down
29 changes: 21 additions & 8 deletions Float.Core.Tests/Float.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>9.0</LangVersion>
<UseMaui>true</UseMaui>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="../stylecop.json" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>../stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NunitXml.TestLogger" Version="3.0.127" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.2.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="coverlet.msbuild" Version="3.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="[5.0.0.1874,6)" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="XunitContext" Version="3.2.5" />
</ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions Float.Core/Analytics/AnalyticsService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
using System;
using System.Collections.Generic;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Storage;
#endif

namespace Float.Core.Analytics
{
Expand All @@ -26,7 +32,11 @@ protected AnalyticsService()
/// </summary>
public static void EnableTracking()
{
#if NETSTANDARD
Application.Current.Properties[SendUsageDataKey] = true;
#else
Preferences.Default.Set(SendUsageDataKey, true);
#endif
}

/// <summary>
Expand All @@ -35,7 +45,11 @@ public static void EnableTracking()
/// </summary>
public static void DisableTracking()
{
#if NETSTANDARD
Application.Current.Properties[SendUsageDataKey] = false;
#else
Preferences.Default.Set(SendUsageDataKey, false);
#endif
}

/// <summary>
Expand All @@ -46,10 +60,17 @@ public static bool IsTrackingEnabled()
{
try
{
#if NETSTANDARD
if (Application.Current?.Properties?.ContainsKey(SendUsageDataKey) == true)
{
return (bool?)Application.Current.Properties[SendUsageDataKey] != false;
}
#else
if (Preferences.Default?.ContainsKey(SendUsageDataKey) == true)
{
return (bool?)Preferences.Default.Get(SendUsageDataKey, true) != false;
}
#endif

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions Float.Core/Commands/DebounceCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System;
using System.Threading.Tasks;
using System.Windows.Input;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Commands
{
Expand Down
5 changes: 5 additions & 0 deletions Float.Core/Commands/SelectViewModelCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System;
using System.Windows.Input;
using Float.Core.ViewModels;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Commands
{
Expand Down
5 changes: 5 additions & 0 deletions Float.Core/Commands/ThrottleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Commands
{
Expand Down
13 changes: 13 additions & 0 deletions Float.Core/Compatibility/DeviceProxy.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Compatibility
{
Expand All @@ -19,7 +24,11 @@ internal static void BeginInvokeOnMainThread(Action action)
{
try
{
#if NETSTANDARD
var method = typeof(Device).GetMethod("BeginInvokeOnMainThread", BindingFlags.Static | BindingFlags.Public);
#else
var method = typeof(Microsoft.Maui.ApplicationModel.MainThread).GetMethod("BeginInvokeOnMainThread", BindingFlags.Static | BindingFlags.Public);
#endif
method?.Invoke(null, new[] { action });
}
catch (Exception e) when (e is TargetInvocationException || e is InvalidOperationException)
Expand All @@ -32,7 +41,11 @@ internal static async Task InvokeOnMainThreadAsync(Action action)
{
try
{
#if NETSTANDARD
var method = typeof(Device).GetMethod("InvokeOnMainThreadAsync", new[] { typeof(Action) });
#else
var method = typeof(Microsoft.Maui.ApplicationModel.MainThread).GetMethod("InvokeOnMainThreadAsync", new[] { typeof(Action) });
#endif
await method?.InvokeAsync(null, new[] { action });
}
catch (Exception e) when (e is TargetInvocationException || e is InvalidOperationException)
Expand Down
9 changes: 7 additions & 2 deletions Float.Core/Float.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2;net6.0;net7.0</TargetFrameworks>
<AssemblyName>Float.Core</AssemblyName>
<AssemblyAuthor>Float</AssemblyAuthor>
<AssemblyDescription>Common utility code used by Float projects.</AssemblyDescription>
Expand All @@ -11,6 +11,9 @@
<Title>$(AssemblyName)</Title>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>9.0</LangVersion>
<ReleaseVersion>1.0.0</ReleaseVersion>
<Version></Version>
<UseMaui>true</UseMaui>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="$(SolutionDir)\stylecop.json" />
Expand All @@ -29,12 +32,14 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Float.TinCan" Version="[1.0.3.29,1.0.4)" />
<PackageReference Include="Float.TinCan" Version="1.0.3.30" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="[12.0.1,]" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
<PackageReference Include="Xamarin.Forms" Version="[5.0.0.1874,6)" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Float.Core/L10n/TranslateExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
using System.Globalization;
using System.Resources;
using Float.Core.Resources;
#if NETSTANDARD
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
#endif

namespace Float.Core.L10n
{
Expand Down
5 changes: 5 additions & 0 deletions Float.Core/Net/OAuth2StrategyAuthCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
using Float.Core.Events;
using Float.Core.Extensions;
using Float.Core.Persistence;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Net
{
Expand Down
4 changes: 2 additions & 2 deletions Float.Core/Net/RequestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Task<Response> Put(string path, Dictionary<string, string> query = null,
/// <param name="body">The Body.</param>
public Task<Response> Patch(string path, HttpContent body)
{
return Send(new HttpMethod("PATCH"), path, null, null, body);
return Send(new HttpMethod("PATCH"), path, null, null, body);
}

/// <summary>
Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task<Response> Send(HttpMethod method, string path, Dictionary<stri

if (query != null)
{
var queryString = string.Join("&", query.Select(kvp => Uri.EscapeUriString(kvp.Key) + "=" + Uri.EscapeUriString(kvp.Value)));
var queryString = string.Join("&", query.Select(kvp => Uri.EscapeDataString(kvp.Key) + "=" + Uri.EscapeDataString(kvp.Value)));
if (url.Query.Contains("?"))
{
url = new Uri(baseUri, $"{path}&{queryString}");
Expand Down
5 changes: 5 additions & 0 deletions Float.Core/Notifications/AlertNotificationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
using Float.Core.Extensions;
using Float.Core.L10n;
using Float.Core.Resources;
#if NETSTANDARD
using Xamarin.Forms;
#else
using Microsoft.Maui;
using Microsoft.Maui.Controls;
#endif

namespace Float.Core.Notifications
{
Expand Down
Loading

0 comments on commit b7e00df

Please sign in to comment.