Skip to content

Commit b7e00df

Browse files
Update for NET6/7 compatibility
1 parent 9bc6084 commit b7e00df

26 files changed

+227
-53
lines changed

.github/workflows/deploy.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
name: Deploy
22

33
on:
4-
workflow_dispatch:
4+
release:
5+
types: [published]
56

67
jobs:
78
deploy:
89
runs-on: ubuntu-latest
910

1011
steps:
11-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1213
with:
1314
fetch-depth: 0
1415
- name: Setup .NET
15-
uses: actions/setup-dotnet@v1
16+
uses: actions/setup-dotnet@v3
1617
with:
17-
dotnet-version: 6.0.x
18-
18+
dotnet-version: |
19+
3.1.x
20+
6.0.x
21+
7.0.x
22+
- name: Retore Workload
23+
run: dotnet workload restore
24+
- name: Restore dependencies
25+
run: dotnet restore
26+
- name: Set Assembly Version
27+
run: ./build.sh --task=GitVersion --configuration=Release
28+
- name: Build Library
29+
run: dotnet build ./Float.Core/Float.Core.csproj --configuration Release --no-restore
30+
- name: Update Version
31+
run: sed -i "s/<Version><\/Version>/<Version>${{ github.event.release.name }}<\/Version>/" ./Float.Core/Float.Core.csproj
32+
- name: Pack and Upload
33+
run: dotnet pack --configuration Release --no-restore
1934
- name: Deploy to NuGet
2035
env:
2136
FLOAT_NUGET_TOKEN: ${{ secrets.FLOAT_NUGET_TOKEN }}
22-
run: ./build.sh --task=Deploy --configuration=Release --nugetUrl="https://api.nuget.org/v3/index.json" --nugetToken="${FLOAT_NUGET_TOKEN}"
37+
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

.github/workflows/test.yml

+23-13
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@ name: Test
22

33
on:
44
pull_request:
5-
branches: [ main ]
5+
branches: [main]
66

77
jobs:
88
test:
9-
109
runs-on: ubuntu-latest
1110

1211
steps:
13-
- uses: actions/checkout@v2
14-
- name: Setup .NET
15-
uses: actions/setup-dotnet@v1
16-
with:
17-
dotnet-version: 6.0.x
18-
- name: Restore dependencies
19-
run: dotnet restore
20-
- name: Build
21-
run: dotnet build --no-restore
22-
- name: Test
23-
run: dotnet test --no-build --verbosity normal
12+
- uses: actions/checkout@v3
13+
- name: Setup .NET
14+
uses: actions/setup-dotnet@v3
15+
with:
16+
dotnet-version: |
17+
3.1.x
18+
6.0.x
19+
7.0.x
20+
- name: Retore Workload
21+
run: dotnet workload restore
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
- name: Build
25+
run: dotnet build --configuration Release --no-restore
26+
- name: Test
27+
run: dotnet test --configuration Release --no-build --verbosity normal --logger:"trx;"
28+
- name: Publish Test Results
29+
uses: EnricoMi/publish-unit-test-result-action@v2
30+
if: always()
31+
with:
32+
files: |
33+
**/TestResults/*.trx

Float.Core.Tests/DebounceCommand.tests.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using System.Threading;
22
using System.Threading.Tasks;
33
using Float.Core.Commands;
4+
#if NETCOREAPP3_1
45
using Xamarin.Forms;
6+
#else
7+
using Microsoft.Maui;
8+
using Microsoft.Maui.Controls;
9+
#endif
510
using Xunit;
611

712
namespace Float.Core.Tests

Float.Core.Tests/Float.Core.Tests.csproj

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
44
<IsPackable>false</IsPackable>
55
<LangVersion>9.0</LangVersion>
6+
<UseMaui>true</UseMaui>
67
</PropertyGroup>
78
<ItemGroup>
89
<AdditionalFiles Include="../stylecop.json" />
910
</ItemGroup>
1011
<PropertyGroup>
1112
<CodeAnalysisRuleSet>../stylecop.ruleset</CodeAnalysisRuleSet>
1213
</PropertyGroup>
13-
<ItemGroup>
14-
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
16-
<PackageReference Include="NunitXml.TestLogger" Version="3.0.127" />
17-
<PackageReference Include="xunit" Version="2.4.2" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
15+
<PackageReference Include="coverlet.collector" Version="6.0.0">
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1917
<PrivateAssets>all</PrivateAssets>
2018
</PackageReference>
21-
<PackageReference Include="coverlet.msbuild" Version="3.2.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PackageReference Include="xunit" Version="2.5.0" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
<PrivateAssets>all</PrivateAssets>
2323
</PackageReference>
24+
</ItemGroup>
25+
<ItemGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">
26+
<PackageReference Include="xunit" Version="2.4.2" />
27+
<PackageReference Include="coverlet.msbuild" Version="3.2.0" />
28+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
29+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
30+
<PrivateAssets>all</PrivateAssets>
31+
</PackageReference>
32+
<PackageReference Include="Xamarin.Forms" Version="[5.0.0.1874,6)" />
33+
</ItemGroup>
34+
<ItemGroup>
35+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
36+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
2437
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
2538
<PackageReference Include="XunitContext" Version="3.2.5" />
2639
</ItemGroup>

Float.Core/Analytics/AnalyticsService.cs

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
#if NETSTANDARD
34
using Xamarin.Forms;
5+
#else
6+
using Microsoft.Maui;
7+
using Microsoft.Maui.Controls;
8+
using Microsoft.Maui.Storage;
9+
#endif
410

511
namespace Float.Core.Analytics
612
{
@@ -26,7 +32,11 @@ protected AnalyticsService()
2632
/// </summary>
2733
public static void EnableTracking()
2834
{
35+
#if NETSTANDARD
2936
Application.Current.Properties[SendUsageDataKey] = true;
37+
#else
38+
Preferences.Default.Set(SendUsageDataKey, true);
39+
#endif
3040
}
3141

3242
/// <summary>
@@ -35,7 +45,11 @@ public static void EnableTracking()
3545
/// </summary>
3646
public static void DisableTracking()
3747
{
48+
#if NETSTANDARD
3849
Application.Current.Properties[SendUsageDataKey] = false;
50+
#else
51+
Preferences.Default.Set(SendUsageDataKey, false);
52+
#endif
3953
}
4054

4155
/// <summary>
@@ -46,10 +60,17 @@ public static bool IsTrackingEnabled()
4660
{
4761
try
4862
{
63+
#if NETSTANDARD
4964
if (Application.Current?.Properties?.ContainsKey(SendUsageDataKey) == true)
5065
{
5166
return (bool?)Application.Current.Properties[SendUsageDataKey] != false;
5267
}
68+
#else
69+
if (Preferences.Default?.ContainsKey(SendUsageDataKey) == true)
70+
{
71+
return (bool?)Preferences.Default.Get(SendUsageDataKey, true) != false;
72+
}
73+
#endif
5374

5475
return true;
5576
}

Float.Core/Commands/DebounceCommand.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using System;
22
using System.Threading.Tasks;
33
using System.Windows.Input;
4+
#if NETSTANDARD
45
using Xamarin.Forms;
6+
#else
7+
using Microsoft.Maui;
8+
using Microsoft.Maui.Controls;
9+
#endif
510

611
namespace Float.Core.Commands
712
{

Float.Core/Commands/SelectViewModelCommand.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using System;
22
using System.Windows.Input;
33
using Float.Core.ViewModels;
4+
#if NETSTANDARD
45
using Xamarin.Forms;
6+
#else
7+
using Microsoft.Maui;
8+
using Microsoft.Maui.Controls;
9+
#endif
510

611
namespace Float.Core.Commands
712
{

Float.Core/Commands/ThrottleCommand.cs

+5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using System.Windows.Input;
5+
#if NETSTANDARD
56
using Xamarin.Forms;
7+
#else
8+
using Microsoft.Maui;
9+
using Microsoft.Maui.Controls;
10+
#endif
611

712
namespace Float.Core.Commands
813
{

Float.Core/Compatibility/DeviceProxy.cs

+13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using System;
22
using System.Reflection;
33
using System.Threading.Tasks;
4+
#if NETSTANDARD
45
using Xamarin.Forms;
6+
#else
7+
using Microsoft.Maui;
8+
using Microsoft.Maui.Controls;
9+
#endif
510

611
namespace Float.Core.Compatibility
712
{
@@ -19,7 +24,11 @@ internal static void BeginInvokeOnMainThread(Action action)
1924
{
2025
try
2126
{
27+
#if NETSTANDARD
2228
var method = typeof(Device).GetMethod("BeginInvokeOnMainThread", BindingFlags.Static | BindingFlags.Public);
29+
#else
30+
var method = typeof(Microsoft.Maui.ApplicationModel.MainThread).GetMethod("BeginInvokeOnMainThread", BindingFlags.Static | BindingFlags.Public);
31+
#endif
2332
method?.Invoke(null, new[] { action });
2433
}
2534
catch (Exception e) when (e is TargetInvocationException || e is InvalidOperationException)
@@ -32,7 +41,11 @@ internal static async Task InvokeOnMainThreadAsync(Action action)
3241
{
3342
try
3443
{
44+
#if NETSTANDARD
3545
var method = typeof(Device).GetMethod("InvokeOnMainThreadAsync", new[] { typeof(Action) });
46+
#else
47+
var method = typeof(Microsoft.Maui.ApplicationModel.MainThread).GetMethod("InvokeOnMainThreadAsync", new[] { typeof(Action) });
48+
#endif
3649
await method?.InvokeAsync(null, new[] { action });
3750
}
3851
catch (Exception e) when (e is TargetInvocationException || e is InvalidOperationException)

Float.Core/Float.Core.csproj

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFrameworks>netstandard2;net6.0;net7.0</TargetFrameworks>
44
<AssemblyName>Float.Core</AssemblyName>
55
<AssemblyAuthor>Float</AssemblyAuthor>
66
<AssemblyDescription>Common utility code used by Float projects.</AssemblyDescription>
@@ -11,6 +11,9 @@
1111
<Title>$(AssemblyName)</Title>
1212
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1313
<LangVersion>9.0</LangVersion>
14+
<ReleaseVersion>1.0.0</ReleaseVersion>
15+
<Version></Version>
16+
<UseMaui>true</UseMaui>
1417
</PropertyGroup>
1518
<ItemGroup>
1619
<AdditionalFiles Include="$(SolutionDir)\stylecop.json" />
@@ -29,12 +32,14 @@
2932
<PackageReadmeFile>readme.md</PackageReadmeFile>
3033
</PropertyGroup>
3134
<ItemGroup>
32-
<PackageReference Include="Float.TinCan" Version="[1.0.3.29,1.0.4)" />
35+
<PackageReference Include="Float.TinCan" Version="1.0.3.30" />
3336
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
3437
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3538
<PrivateAssets>all</PrivateAssets>
3639
</PackageReference>
3740
<PackageReference Include="Newtonsoft.Json" Version="[12.0.1,]" />
41+
</ItemGroup>
42+
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
3843
<PackageReference Include="Xamarin.Forms" Version="[5.0.0.1874,6)" />
3944
</ItemGroup>
4045
<ItemGroup>

Float.Core/L10n/TranslateExtension.cs

+6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
using System.Globalization;
44
using System.Resources;
55
using Float.Core.Resources;
6+
#if NETSTANDARD
67
using Xamarin.Forms;
78
using Xamarin.Forms.Xaml;
9+
#else
10+
using Microsoft.Maui;
11+
using Microsoft.Maui.Controls;
12+
using Microsoft.Maui.Controls.Xaml;
13+
#endif
814

915
namespace Float.Core.L10n
1016
{

Float.Core/Net/OAuth2StrategyAuthCode.cs

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
using Float.Core.Events;
77
using Float.Core.Extensions;
88
using Float.Core.Persistence;
9+
#if NETSTANDARD
910
using Xamarin.Forms;
11+
#else
12+
using Microsoft.Maui;
13+
using Microsoft.Maui.Controls;
14+
#endif
1015

1116
namespace Float.Core.Net
1217
{

Float.Core/Net/RequestClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Task<Response> Put(string path, Dictionary<string, string> query = null,
103103
/// <param name="body">The Body.</param>
104104
public Task<Response> Patch(string path, HttpContent body)
105105
{
106-
return Send(new HttpMethod("PATCH"), path, null, null, body);
106+
return Send(new HttpMethod("PATCH"), path, null, null, body);
107107
}
108108

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

141141
if (query != null)
142142
{
143-
var queryString = string.Join("&", query.Select(kvp => Uri.EscapeUriString(kvp.Key) + "=" + Uri.EscapeUriString(kvp.Value)));
143+
var queryString = string.Join("&", query.Select(kvp => Uri.EscapeDataString(kvp.Key) + "=" + Uri.EscapeDataString(kvp.Value)));
144144
if (url.Query.Contains("?"))
145145
{
146146
url = new Uri(baseUri, $"{path}&{queryString}");

Float.Core/Notifications/AlertNotificationHandler.cs

+5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
using Float.Core.Extensions;
44
using Float.Core.L10n;
55
using Float.Core.Resources;
6+
#if NETSTANDARD
67
using Xamarin.Forms;
8+
#else
9+
using Microsoft.Maui;
10+
using Microsoft.Maui.Controls;
11+
#endif
712

813
namespace Float.Core.Notifications
914
{

0 commit comments

Comments
 (0)