Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to WinAppSDK 1.5 and .NET8; PublishSingleFile for unpackaged configs; fix compile warnings #1483

Merged
merged 10 commits into from
Mar 12, 2024
14 changes: 8 additions & 6 deletions WinUIGallery/Common/SuspensionManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -47,15 +45,17 @@ public static Dictionary<string, object> SessionState
public static List<Type> KnownTypes
{
get { return _knownTypes; }
}

}
/// <summary>
/// Save the current <see cref="SessionState"/>. Any <see cref="Frame"/> instances
/// registered with <see cref="RegisterFrame"/> will also preserve their current
/// navigation stack, which in turn gives their active <see cref="Page"/> an opportunity
/// to save its state.
/// </summary>
/// <returns>An asynchronous task that reflects when session state has been saved.</returns>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026",
Justification = "From manual inspection, _sessionState only serializes Dictionaries of strings")]
public static async Task SaveAsync()
{
try
Expand All @@ -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<string, object>), _knownTypes);
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, object>), _knownTypes);
serializer.WriteObject(sessionData, _sessionState);

// Get an output stream for the SessionState file and write the state asynchronously
Expand All @@ -99,6 +99,8 @@ public static async Task SaveAsync()
/// <returns>An asynchronous task that reflects when session state has been read. The
/// content of <see cref="SessionState"/> should not be relied upon until this task
/// completes.</returns>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026",
Justification = "From manual inspection, _sessionState only serializes Dictionaries of strings")]
public static async Task RestoreAsync()
{
_sessionState = new Dictionary<string, object>();
Expand Down
1 change: 0 additions & 1 deletion WinUIGallery/ControlPages/DesignGuidance/IconsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public sealed partial class IconsPage : Page
};

private string currentSearch = null;
private Thread searchThread = null;

public IconData SelectedItem
{
Expand Down
17 changes: 11 additions & 6 deletions WinUIGallery/DataModel/ControlInfoDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,6 +31,12 @@ public class Root
{
public ObservableCollection<ControlInfoDataGroup> Groups { get; set; }
}
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
[JsonSerializable(typeof(Root))]
internal partial class RootContext : JsonSerializerContext
{
}

/// <summary>
/// Generic item data model.
/// </summary>
Expand Down Expand Up @@ -173,11 +181,8 @@ private async Task GetControlInfoDataAsync()
}
}

var jsonText = await FileLoader.LoadText("DataModel/ControlInfoData.json");
var controlInfoDataGroup = JsonSerializer.Deserialize<Root>(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)
{
Expand Down
13 changes: 8 additions & 5 deletions WinUIGallery/DataModel/IconsDataSource.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<IconData>))]
internal partial class IconDataListContext : JsonSerializerContext
{
}

internal class IconsDataSource
Expand Down Expand Up @@ -41,11 +47,8 @@ public async Task<List<IconData>> LoadIcons()
lock (_lock)
{
if (icons.Count == 0)
{
icons = JsonSerializer.Deserialize<List<IconData>>(jsonText, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
{
icons = JsonSerializer.Deserialize(jsonText, typeof(List<IconData>), IconDataListContext.Default) as List<IconData>;
}
return icons;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>ARM64</Platform>
<RuntimeIdentifier>win10-arm64</RuntimeIdentifier>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<!--NOTE: this refers to .NET (not WinAppSDK) self-containment which must always be true,
since there is no Windows framework package available for .NET 5+ -->
<SelfContained>True</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishAppxPackage>True</PublishAppxPackage>
<PublishAppxPackage>$(Packaged)</PublishAppxPackage>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>$(Optimized)</PublishTrimmed>
<!--With .NET 7, trimming mode default changed from partial to full which is more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x64</Platform>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<!--NOTE: this refers to .NET (not WinAppSDK) self-containment which must always be true,
since there is no Windows framework package available for .NET 5+ -->
<SelfContained>True</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishAppxPackage>True</PublishAppxPackage>
<PublishAppxPackage>$(Packaged)</PublishAppxPackage>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>$(Optimized)</PublishTrimmed>
<!--With .NET 7, trimming mode default changed from partial to full which is more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x86</Platform>
<RuntimeIdentifier>win10-x86</RuntimeIdentifier>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<!--NOTE: this refers to .NET (not WinAppSDK) self-containment which must always be true,
since there is no Windows framework package available for .NET 5+ -->
<SelfContained>True</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishAppxPackage>True</PublishAppxPackage>
<PublishAppxPackage>$(Packaged)</PublishAppxPackage>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>$(Optimized)</PublishTrimmed>
<!--With .NET 7, trimming mode default changed from partial to full which is more
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

53 changes: 37 additions & 16 deletions WinUIGallery/WinUIGallery.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.0.1" />
<PropertyGroup>
<TargetFramework>$(SamplesTargetFrameworkMoniker)</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<OutputType>WinExe</OutputType>
<TargetFramework>$(SamplesTargetFrameworkMoniker)</TargetFramework>
<TargetPlatformVersion>$(WindowsSdkTargetPlatformVersion)</TargetPlatformVersion>
<TargetPlatformMinVersion>$(WindowsAppSdkTargetPlatformVersion)</TargetPlatformMinVersion>
<UseWinUI>true</UseWinUI>
<DefineConstants Condition="'$(WindowsAppSdkSelfContained)'==''">$(DefineConstants);WindowsAppSdkRuntimeDependent</DefineConstants>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<NoWarn>8305</NoWarn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<NoWarn>
0108; <!-- 'x' hides inherited member 'y'. Use the new keyword if hiding was intended. -->
8305 <!-- 'x' is for evaluation purposes only and is subject to change or removal in future updates. -->
Expand All @@ -26,19 +26,25 @@
<Packaged Condition="'$(Configuration)' == 'Debug-Unpackaged' Or '$(Configuration)' == 'Release-Unpackaged'">false</Packaged>
<Optimized>true</Optimized>
<Optimized Condition="'$(Configuration)' == 'Debug-Unpackaged' Or '$(Configuration)' == 'Debug'">false</Optimized>
<!-- In .NET 8, serialization is prohibited by default - we can safely use it since we're not dealing with UDTs. -->
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<SingleProject>true</SingleProject>
<SingleProject Condition="'$(SolutionName)' == 'WinUIGallery.DesktopWap'">false</SingleProject>
<WindowsAppSdkIncludeVersionInfo>true</WindowsAppSdkIncludeVersionInfo>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<PublishSingleFile Condition="'$(PublishSingleFile)' == '' and '$(Packaged)' != 'true'">true</PublishSingleFile>
<WindowsAppSdkSelfContained Condition="'$(WindowsAppSdkSelfContained)' == '' and '$(PublishSingleFile)' == 'true'">true</WindowsAppSdkSelfContained>
<!-- Enable ExplicitlyIncludeVersionInfo workaround by setting WindowsAppSdkSelfContained earlier than the mock package would -->
<WindowsAppSdkSelfContained Condition="'$(IsInWinUIRepo)' == 'true' and '$(WindowsAppSdkSelfContained)'==''">true</WindowsAppSdkSelfContained>
</PropertyGroup>

<PropertyGroup Condition="'$(Packaged)' != 'true' and '$(SingleProject)'=='true'">
<PublishProfile>win10-$(Platform)-unpackaged.pubxml</PublishProfile>
<EnableMsixTooling>false</EnableMsixTooling>
<EnableMsixTooling Condition="'$(PublishSingleFile)'=='true'">true</EnableMsixTooling>
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>

<PropertyGroup Condition="'$(Packaged)' == 'true' and '$(SingleProject)'=='true'">
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<WindowsPackageType>MSIX</WindowsPackageType>
<AppxBundleNameForOutput>WinUIGallery</AppxBundleNameForOutput>
<EnableMsixTooling>true</EnableMsixTooling>
Expand All @@ -60,7 +66,7 @@
<PackageCertificateKeyFile Condition="Exists('$(PfxFile)')">$(PfxFile)</PackageCertificateKeyFile>
</PropertyGroup>

<ItemGroup Condition="'$(SingleProject)'=='true'">
<ItemGroup Condition="'$(Packaged)' == 'true' and '$(SingleProject)'=='true'">
<AppxManifest Include="Package.appxmanifest" Condition="'$(Release)' == 'true'">
<SubType>Designer</SubType>
</AppxManifest>
Expand All @@ -85,6 +91,7 @@
<EmbeddedResource Remove="Assets\ControlIcons\**" />
<None Remove="Assets\ControlIcons\**" />
<Page Remove="Assets\ControlIcons\**" />
<PRIResource Remove="Assets\ControlIcons\**" />
</ItemGroup>

<!-- In the WinUI repo, package reference versions are controlled centrally by a Packages.props. We will
Expand Down Expand Up @@ -175,6 +182,7 @@
<Content Include="Assets\Typography.light.png" />
<Content Include="ControlPagesSampleCode\Icons\FontIconSample2_xaml.txt" />
<Content Include="DataModel\IconsData.json" />
<Content Include="DataModel\ControlInfoData.json" />
</ItemGroup>
<ItemGroup>
<Content Include="ControlPagesSampleCode\Typography\TypographySample_xaml.txt" />
Expand Down Expand Up @@ -255,18 +263,31 @@
<Page Update="Controls\DesignGuidance\ColorSections\TextSection.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="ControlPages\SelectorBarPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="SamplePages\SampleBuiltInSystemBackdropsWindow.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>
<Import Project="ContentIncludes.props" />
<ItemGroup>
<PRIResource Remove="Assets\ControlIcons\**" />
</ItemGroup>
<ItemGroup>
<Page Update="ControlPages\SelectorBarPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<!--Per comment in Microsoft.Common.CurrentVersion.targets, the default GetCopyToPublishDirectoryItems
just returns GetCopyToOutputDirectoryItems, which automatically includes the ContentWithTargetPath
and _NoneWithTargetPath items in the MSIX package. The .NET GetCopyToPublishDirectoryItems
overrides this and drops all these items unless they're specifically set to copy to the output
directory. The default behavior is easier, so we'll mimic that here.-->
<Target Name="AddCopyToPublishDirectoryItems" Condition="'$(PublishSingleFile)'=='true'" BeforeTargets="GetCopyToPublishDirectoryItems" DependsOnTargets="AssignTargetPaths">
<ItemGroup>
<CurrentContentWithTargetPath Include="@(ContentWithTargetPath)"/>
<ContentWithTargetPath Remove="@(CurrentContentWithTargetPath )"/>
<ContentWithTargetPath Include="@(CurrentContentWithTargetPath )">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ContentWithTargetPath>
<CurrentNoneWithTargetPath Include="@(_NoneWithTargetPath)"/>
<_NoneWithTargetPath Remove="@(CurrentNoneWithTargetPath )"/>
<_NoneWithTargetPath Include="@(CurrentNoneWithTargetPath )">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</_NoneWithTargetPath>
</ItemGroup>
</Target>
</Project>
4 changes: 3 additions & 1 deletion WinUIGallery/standalone.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project>
<PropertyGroup>
<!-- The NuGet versions of dependencies to build against. -->
<SamplesTargetFrameworkMoniker>net7.0-windows10.0.19041.0</SamplesTargetFrameworkMoniker>
<SamplesTargetFrameworkMoniker>net8.0-windows10.0.22621.0</SamplesTargetFrameworkMoniker>
<WindowsAppSdkPackageVersion>1.5.240227000</WindowsAppSdkPackageVersion>
<MicrosoftNETCoreUniversalWindowsPlatformVersion>6.2.11</MicrosoftNETCoreUniversalWindowsPlatformVersion>
<GraphicsWin2DVersion>1.0.4</GraphicsWin2DVersion>
<ColorCodeVersion>2.0.13</ColorCodeVersion>
<CommunityToolkitWinUIVersion>8.0.230907</CommunityToolkitWinUIVersion>
<WindowsSdkTargetPlatformVersion>10.0.22621.756</WindowsSdkTargetPlatformVersion>
<MicrosoftWindowsSDKBuildToolsNugetPackageVersion>10.0.22621.756</MicrosoftWindowsSDKBuildToolsNugetPackageVersion>
<WindowsAppSdkTargetPlatformVersion>10.0.17763.0</WindowsAppSdkTargetPlatformVersion>
<MicrosoftCsWinRTPackageVersion>2.0.3</MicrosoftCsWinRTPackageVersion>
<!-- We have multiple projects in the same directory, which means we need to separate their output paths-->
<BaseIntermediateOutputPath>obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
Expand Down
2 changes: 1 addition & 1 deletion WinUIGalleryUnitTests/WinUIGalleryUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RootNamespace>WinUIGalleryUnitTests</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
Expand Down