From 2f7da4d9707155f4e27d6e5faec26c53cbddc686 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Tue, 12 Mar 2024 10:40:00 -0700 Subject: [PATCH] Update to WinAppSDK 1.5 and .NET8; PublishSingleFile for unpackaged configs; fix compile warnings (#1483) --- WinUIGallery/Common/SuspensionManager.cs | 14 ++--- .../DesignGuidance/IconsPage.xaml.cs | 1 - .../DataModel/ControlInfoDataSource.cs | 17 +++--- WinUIGallery/DataModel/IconsDataSource.cs | 13 +++-- .../{win10-arm64.pubxml => win-arm64.pubxml} | 5 +- .../{win10-x64.pubxml => win-x64.pubxml} | 5 +- .../{win10-x86.pubxml => win-x86.pubxml} | 5 +- .../win10-arm64-unpackaged.pubxml | 22 -------- .../win10-x64-unpackaged.pubxml | 22 -------- .../win10-x86-unpackaged.pubxml | 22 -------- .../WinUIGallery.DesktopWap.Package.wapproj | 4 +- WinUIGallery/WinUIGallery.csproj | 53 +++++++++++++------ WinUIGallery/standalone.props | 4 +- .../WinUIGalleryUnitTests.csproj | 2 +- azure-pipelines.yml | 2 +- 15 files changed, 77 insertions(+), 114 deletions(-) rename WinUIGallery/Properties/PublishProfiles/{win10-arm64.pubxml => win-arm64.pubxml} (85%) rename WinUIGallery/Properties/PublishProfiles/{win10-x64.pubxml => win-x64.pubxml} (83%) rename WinUIGallery/Properties/PublishProfiles/{win10-x86.pubxml => win-x86.pubxml} (83%) delete mode 100644 WinUIGallery/Properties/PublishProfiles/win10-arm64-unpackaged.pubxml delete mode 100644 WinUIGallery/Properties/PublishProfiles/win10-x64-unpackaged.pubxml delete mode 100644 WinUIGallery/Properties/PublishProfiles/win10-x86-unpackaged.pubxml diff --git a/WinUIGallery/Common/SuspensionManager.cs b/WinUIGallery/Common/SuspensionManager.cs index ab77f3baf..74057b0f1 100644 --- a/WinUIGallery/Common/SuspensionManager.cs +++ b/WinUIGallery/Common/SuspensionManager.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; -using System.Text; using System.Threading.Tasks; -using Windows.ApplicationModel; using Windows.Storage; using Windows.Storage.Streams; using Microsoft.UI.Xaml; @@ -47,8 +45,8 @@ public static Dictionary SessionState public static List KnownTypes { get { return _knownTypes; } - } - + } + /// /// Save the current . Any instances /// registered with will also preserve their current @@ -56,6 +54,8 @@ public static List KnownTypes /// to save its state. /// /// An asynchronous task that reflects when session state has been saved. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + Justification = "From manual inspection, _sessionState only serializes Dictionaries of strings")] public static async Task SaveAsync() { try @@ -72,7 +72,7 @@ public static async Task SaveAsync() // Serialize the session state synchronously to avoid asynchronous access to shared // state MemoryStream sessionData = new MemoryStream(); - DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary), _knownTypes); + DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary), _knownTypes); serializer.WriteObject(sessionData, _sessionState); // Get an output stream for the SessionState file and write the state asynchronously @@ -99,6 +99,8 @@ public static async Task SaveAsync() /// An asynchronous task that reflects when session state has been read. The /// content of should not be relied upon until this task /// completes. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + Justification = "From manual inspection, _sessionState only serializes Dictionaries of strings")] public static async Task RestoreAsync() { _sessionState = new Dictionary(); diff --git a/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml.cs b/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml.cs index 8758d6a03..fa169732f 100644 --- a/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml.cs +++ b/WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml.cs @@ -33,7 +33,6 @@ public sealed partial class IconsPage : Page }; private string currentSearch = null; - private Thread searchThread = null; public IconData SelectedItem { diff --git a/WinUIGallery/DataModel/ControlInfoDataSource.cs b/WinUIGallery/DataModel/ControlInfoDataSource.cs index ae918a8dd..ab2c20452 100644 --- a/WinUIGallery/DataModel/ControlInfoDataSource.cs +++ b/WinUIGallery/DataModel/ControlInfoDataSource.cs @@ -11,9 +11,11 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using WinUIGallery.Common; -using System.Text.Json; +using WinUIGallery.DesktopWap.DataModel; // The data model defined by this file serves as a representative example of a strongly-typed // model. The property names chosen coincide with data bindings in the standard item templates. @@ -29,6 +31,12 @@ public class Root { public ObservableCollection Groups { get; set; } } + [JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)] + [JsonSerializable(typeof(Root))] + internal partial class RootContext : JsonSerializerContext + { + } + /// /// Generic item data model. /// @@ -173,11 +181,8 @@ private async Task GetControlInfoDataAsync() } } - var jsonText = await FileLoader.LoadText("DataModel/ControlInfoData.json"); - var controlInfoDataGroup = JsonSerializer.Deserialize(jsonText, new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true - }); + var jsonText = await FileLoader.LoadText("DataModel/ControlInfoData.json"); + var controlInfoDataGroup = JsonSerializer.Deserialize(jsonText, typeof(Root), RootContext.Default) as Root; lock (_lock) { diff --git a/WinUIGallery/DataModel/IconsDataSource.cs b/WinUIGallery/DataModel/IconsDataSource.cs index 154ede730..1246b4618 100644 --- a/WinUIGallery/DataModel/IconsDataSource.cs +++ b/WinUIGallery/DataModel/IconsDataSource.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using WinUIGallery.Common; @@ -14,6 +15,11 @@ public class IconData public string Character => char.ConvertFromUtf32(Convert.ToInt32(Code, 16)); public string CodeGlyph => "\\u" + Code; public string TextGlyph => "&#x" + Code + ";"; + } + [JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)] + [JsonSerializable(typeof(List))] + internal partial class IconDataListContext : JsonSerializerContext + { } internal class IconsDataSource @@ -41,11 +47,8 @@ public async Task> LoadIcons() lock (_lock) { if (icons.Count == 0) - { - icons = JsonSerializer.Deserialize>(jsonText, new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true - }); + { + icons = JsonSerializer.Deserialize(jsonText, typeof(List), IconDataListContext.Default) as List; } return icons; } diff --git a/WinUIGallery/Properties/PublishProfiles/win10-arm64.pubxml b/WinUIGallery/Properties/PublishProfiles/win-arm64.pubxml similarity index 85% rename from WinUIGallery/Properties/PublishProfiles/win10-arm64.pubxml rename to WinUIGallery/Properties/PublishProfiles/win-arm64.pubxml index 7777f0dc8..d29f86495 100644 --- a/WinUIGallery/Properties/PublishProfiles/win10-arm64.pubxml +++ b/WinUIGallery/Properties/PublishProfiles/win-arm64.pubxml @@ -6,12 +6,11 @@ https://go.microsoft.com/fwlink/?LinkID=208121. FileSystem ARM64 - win10-arm64 + win-arm64 True - False - True + $(Packaged) False $(Optimized) True - False - True + $(Packaged) False $(Optimized) True - False - True + $(Packaged) False $(Optimized) - - - FileSystem - ARM64 - win10-arm64 - - True - False - False - False - $(Optimized) - - partial - - \ No newline at end of file diff --git a/WinUIGallery/Properties/PublishProfiles/win10-x64-unpackaged.pubxml b/WinUIGallery/Properties/PublishProfiles/win10-x64-unpackaged.pubxml deleted file mode 100644 index 0b74be333..000000000 --- a/WinUIGallery/Properties/PublishProfiles/win10-x64-unpackaged.pubxml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - FileSystem - x64 - win10-x64 - - True - False - False - False - $(Optimized) - - partial - - \ No newline at end of file diff --git a/WinUIGallery/Properties/PublishProfiles/win10-x86-unpackaged.pubxml b/WinUIGallery/Properties/PublishProfiles/win10-x86-unpackaged.pubxml deleted file mode 100644 index 2bda3fa70..000000000 --- a/WinUIGallery/Properties/PublishProfiles/win10-x86-unpackaged.pubxml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - FileSystem - x86 - win10-x86 - - True - False - False - False - $(Optimized) - - partial - - \ No newline at end of file diff --git a/WinUIGallery/WinUIGallery.DesktopWap.Package.wapproj b/WinUIGallery/WinUIGallery.DesktopWap.Package.wapproj index 09c1142ea..0b14e7b1a 100644 --- a/WinUIGallery/WinUIGallery.DesktopWap.Package.wapproj +++ b/WinUIGallery/WinUIGallery.DesktopWap.Package.wapproj @@ -38,7 +38,7 @@ 4c7b20d7-5f5c-440e-8da3-b19a328cc8bd - 10.0.19041.0 + 10.0.22621.0 10.0.17763.0 en-US True @@ -90,7 +90,7 @@ True - Properties\PublishProfiles\win10-$(Platform).pubxml + Properties\PublishProfiles\win-$(Platform).pubxml diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index 719e16d30..89f3ece52 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -1,16 +1,16 @@  - $(SamplesTargetFrameworkMoniker) - 10.0.17763.0 WinExe + $(SamplesTargetFrameworkMoniker) + $(WindowsSdkTargetPlatformVersion) + $(WindowsAppSdkTargetPlatformVersion) true - $(DefineConstants);WindowsAppSdkRuntimeDependent app.manifest x86;x64;ARM64 8305 false - win10-x86;win10-x64;win10-arm64 + win-x86;win-x64;win-arm64 0108; 8305 @@ -26,19 +26,25 @@ false true false + + true true false true + win-$(Platform).pubxml + true + true + + true - win10-$(Platform)-unpackaged.pubxml false + true None - win10-$(Platform).pubxml MSIX WinUIGallery true @@ -60,7 +66,7 @@ $(PfxFile) - + Designer @@ -85,6 +91,7 @@ + + + + + + + PreserveNewest + + + <_NoneWithTargetPath Remove="@(CurrentNoneWithTargetPath )"/> + <_NoneWithTargetPath Include="@(CurrentNoneWithTargetPath )"> + PreserveNewest + + + \ No newline at end of file diff --git a/WinUIGallery/standalone.props b/WinUIGallery/standalone.props index f093015f5..b7e637862 100644 --- a/WinUIGallery/standalone.props +++ b/WinUIGallery/standalone.props @@ -1,13 +1,15 @@ - net7.0-windows10.0.19041.0 + net8.0-windows10.0.22621.0 1.5.240227000 6.2.11 1.0.4 2.0.13 8.0.230907 + 10.0.22621.756 10.0.22621.756 + 10.0.17763.0 2.0.3 obj\$(MSBuildProjectName)\ diff --git a/WinUIGalleryUnitTests/WinUIGalleryUnitTests.csproj b/WinUIGalleryUnitTests/WinUIGalleryUnitTests.csproj index 34686ce15..296a6dd6f 100644 --- a/WinUIGalleryUnitTests/WinUIGalleryUnitTests.csproj +++ b/WinUIGalleryUnitTests/WinUIGalleryUnitTests.csproj @@ -7,7 +7,7 @@ WinUIGalleryUnitTests app.manifest x86;x64;ARM64 - win10-x86;win10-x64;win10-arm64 + win-x86;win-x64;win-arm64 win-$(Platform).pubxml true true diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8f2274c05..d25204f60 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -37,7 +37,7 @@ steps: command: 'publish' publishWebProjects: false projects: '$(solutionGallery)' - arguments: '/p:AppxPackageDir="D:\a\1\a\AppxPackages\\" /p:platform="$(buildPlatform)" /p:PublishProfile="./WinUIGallery/Properties/PublishProfiles/win10-$(buildPlatform).pubxml"' + arguments: '/p:AppxPackageDir="D:\a\1\a\AppxPackages\\" /p:platform="$(buildPlatform)" /p:configuration="$(buildConfiguration)" /p:PublishProfile="./WinUIGallery/Properties/PublishProfiles/win-$(buildPlatform).pubxml"' zipAfterPublish: false modifyOutputPath: false