Skip to content

Commit

Permalink
Migrate to .NET8 (#536)
Browse files Browse the repository at this point in the history
* Bump dotnet version

* Bump target framework to .net8

* Migrate Microsoft.Maui.Essentials to use as explicit NuGet packages

* Remove obsoleted binary serialization for BiDictionary

* Cleanup

* Migrate Maui to use as explicit NuGet package

* Sync target frameworks and min supported os

* Use the same MAUI version in all projects

* Bump .NET8 to stable

* Update pipelines env

* Bump iOS target framework for latest maui & essentials

* Resolve warnings related to supported versions

* Update nuget package

* Sync versions
  • Loading branch information
wcoder authored Dec 27, 2023
1 parent 84e4ef3 commit 1e59f30
Show file tree
Hide file tree
Showing 39 changed files with 85 additions and 142 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<LangVersion>10.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<DebugType>portable</DebugType>
<MauiVersion>8.0.3</MauiVersion>
</PropertyGroup>

<!-- Assembly Info -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android33.0</TargetFramework>
<TargetFramework>net8.0-android34.0</TargetFramework>
<SupportedOSPlatformVersion>21.0</SupportedOSPlatformVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>disable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-ios12.0</TargetFramework>
<TargetFramework>net8.0-ios12.0</TargetFramework>
<SupportedOSPlatformVersion>10.0</SupportedOSPlatformVersion>
<CreatePackage>false</CreatePackage>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Softeq.XToolkit.Bindings/Softeq.XToolkit.Bindings.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android33.0</TargetFramework>
<TargetFramework>net8.0-android34.0</TargetFramework>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>disable</ImplicitUsings>

Expand Down Expand Up @@ -36,16 +35,14 @@

<ItemGroup>
<PackageReference Include="Xunit.Combinatorial" Version="1.5.25" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<ProjectReference Include="..\Softeq.XToolkit.Common.Droid\Softeq.XToolkit.Common.Droid.csproj" />
</ItemGroup>

<ItemGroup>
<MauiPlatformSpecificFolder Remove="Platforms\iOS\" />
</ItemGroup>

<Import Project="..\_Tests.Platform.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android33.0</TargetFramework>
<TargetFramework>net8.0-android34.0</TargetFramework>
<SupportedOSPlatformVersion>21.0</SupportedOSPlatformVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using Softeq.XToolkit.Common.Collections;
using Xunit;

namespace Softeq.XToolkit.Common.Tests.Collections.BiDictionaryTests
Expand Down Expand Up @@ -141,29 +138,6 @@ public void Remove_Negative()
Assert.Equal("[0, 0],[1, 1]-[0, 0],[1, 1]", dictionary.GetResult());
}

[Fact]
public void Serialization()
{
var dictionary = BiDictionaryHelper.CreateWithTwoItems();

var sb = new StringBuilder();

using (var memoryStream = new MemoryStream())
{
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, dictionary);
memoryStream.Position = 0;

var newDict = (BiDictionary<int, string>) binaryFormatter.Deserialize(memoryStream);

sb.AppendJoin(",", newDict);
sb.Append("-");
sb.AppendJoin(",", newDict.Reverse);
}

Assert.Equal("[0, 0],[1, 1]-[0, 0],[1, 1]", sb.ToString());
}

[Fact]
public void Set()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-ios15.0</TargetFramework>
<TargetFramework>net8.0-ios17.0</TargetFramework>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>disable</ImplicitUsings>

Expand Down Expand Up @@ -36,6 +35,8 @@

<ItemGroup>
<PackageReference Include="Xunit.Combinatorial" Version="1.5.25" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-ios12.0</TargetFramework>
<TargetFramework>net8.0-ios12.0</TargetFramework>
<SupportedOSPlatformVersion>10.0</SupportedOSPlatformVersion>
<CreatePackage>false</CreatePackage>
</PropertyGroup>
Expand Down
55 changes: 1 addition & 54 deletions Softeq.XToolkit.Common/Collections/BiDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Permissions;

#pragma warning disable CS1591

namespace Softeq.XToolkit.Common.Collections
{
[Serializable]
public class BiDictionary<TFirst, TSecond> :
IDictionary<TFirst, TSecond>, IReadOnlyDictionary<TFirst, TSecond>,
IDictionary,
ISerializable
IDictionary
{
private readonly IDictionary<TFirst, TSecond> _firstToSecond = new Dictionary<TFirst, TSecond>();

Expand All @@ -33,24 +27,6 @@ public BiDictionary()
_reverseDictionary = new ReverseDictionary(this);
}

protected BiDictionary(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}

var data = (byte[]) info.GetValue("firstToSecond", typeof(byte[]));
using (var memoryStream = new MemoryStream(data))
{
var binaryFormatter = new BinaryFormatter();
_firstToSecond = (Dictionary<TFirst, TSecond>) binaryFormatter.Deserialize(memoryStream);
}

_secondToFirst = new Dictionary<TSecond, TFirst>();
_reverseDictionary = new ReverseDictionary(this);
}

public int Count => _firstToSecond.Count;

public bool IsReadOnly => _firstToSecond.IsReadOnly || _secondToFirst.IsReadOnly;
Expand Down Expand Up @@ -196,35 +172,6 @@ void ICollection<KeyValuePair<TFirst, TSecond>>.CopyTo(KeyValuePair<TFirst, TSec
_firstToSecond.CopyTo(array, arrayIndex);
}

[SecurityPermission(
SecurityAction.LinkDemand,
Flags = SecurityPermissionFlag.SerializationFormatter)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}

using (var memoryStream = new MemoryStream())
{
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, _firstToSecond);
var array = memoryStream.ToArray();
info.AddValue("firstToSecond", array, typeof(byte[]));
}
}

[OnDeserialized]
internal void OnDeserialized(StreamingContext context)
{
_secondToFirst.Clear();
foreach (var item in _firstToSecond)
{
_secondToFirst.Add(item.Value, item.Key);
}
}

private static KeyValuePair<TItem, TKey> ReverseItem<TKey, TItem>(KeyValuePair<TKey, TItem> item)
{
return new KeyValuePair<TItem, TKey>(item.Value, item.Key);
Expand Down
2 changes: 1 addition & 1 deletion Softeq.XToolkit.Common/Softeq.XToolkit.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-ios12.0</TargetFramework>
<TargetFramework>net8.0-ios17.0</TargetFramework>
<SupportedOSPlatformVersion>12.0</SupportedOSPlatformVersion>
<UseMauiEssentials>true</UseMauiEssentials>
<CreatePackage>false</CreatePackage>
</PropertyGroup>

Expand All @@ -20,4 +19,8 @@
<ProjectReference Include="..\Softeq.XToolkit.Connectivity\Softeq.XToolkit.Connectivity.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UseMauiEssentials>true</UseMauiEssentials>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -13,4 +12,8 @@
<ProjectReference Include="..\Softeq.XToolkit.Common\Softeq.XToolkit.Common.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public override (string, bool)[] RequiredPermissions
get
{
#if __ANDROID_33__
#pragma warning disable CA1416
var isSupport =
SdkVersion.IsBuildVersionAtLeast(BuildVersionCodes.Tiramisu) &&
SdkVersion.IsDeviceVersionAtLeast(BuildVersionCodes.Tiramisu) &&
Expand All @@ -24,10 +25,11 @@ public override (string, bool)[] RequiredPermissions
return isSupport ?
new (string, bool)[] { (Manifest.Permission.PostNotifications, true) } :
System.Array.Empty<(string, bool)>();
#pragma warning restore CA1416
#else
return new (string, bool)[] { };
#endif
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android33.0</TargetFramework>
<TargetFramework>net8.0-android34.0</TargetFramework>
<SupportedOSPlatformVersion>21.0</SupportedOSPlatformVersion>
<UseMauiEssentials>true</UseMauiEssentials>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -24,4 +23,8 @@
<ProjectReference Include="..\Softeq.XToolkit.Permissions\Softeq.XToolkit.Permissions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-ios13.0</TargetFramework>
<TargetFramework>net8.0-ios17.0</TargetFramework>
<SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion>
<UseMauiEssentials>true</UseMauiEssentials>
<CreatePackage>false</CreatePackage>
</PropertyGroup>

Expand All @@ -22,5 +21,6 @@

<ItemGroup>
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions Softeq.XToolkit.Permissions/Softeq.XToolkit.Permissions.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UseMauiEssentials>true</UseMauiEssentials>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-android33.0</TargetFramework>
<TargetFramework>net8.0-android34.0</TargetFramework>
<SupportedOSPlatformVersion>26.0</SupportedOSPlatformVersion>
</PropertyGroup>

Expand All @@ -27,7 +27,7 @@
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.5.0" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Process" Version="2.5.1" />
<PackageReference Include="Xamarin.Firebase.Messaging" Version="123.0.8" />
<PackageReference Include="Xamarin.ShortcutBadger" Version="1.1.21" />
<PackageReference Include="Xamarin.ShortcutBadger" Version="1.1.21.80" />
</ItemGroup>

</Project>
Loading

0 comments on commit 1e59f30

Please sign in to comment.