Skip to content

Commit

Permalink
Enable NativeAot support for all projects, add net8.0 target, rewrite…
Browse files Browse the repository at this point in the history
… DataGrid styles autoincluding in MaterialToolKit #232
  • Loading branch information
SKProCH committed Feb 10, 2024
1 parent aa995ea commit f00728c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<Import Project="SourceLink.props" Condition="'$(DisableSourceLink)' == ''"/>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>NU5104, NU1507</NoWarn>
Expand Down Expand Up @@ -33,5 +32,8 @@

<PropertyGroup>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions Material.Avalonia.DataGrid/Material.Avalonia.DataGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<Description>DataGrid styles library of Material.Avalonia.</Description>
<PackageTags>avalonia xaml material design theme datagrid colour color ui ux material-design google-material</PackageTags>
<PackageIcon>FavIcon.png</PackageIcon>

<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Material.Avalonia.Dialogs/Material.Avalonia.Dialogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<Description>Material.Dialog provide some essential material dialogs for use.</Description>
<PackageTags>avalonia xaml material design theme dialogs colour color ui ux material-design google-material</PackageTags>
<PackageIcon>FavIcon.png</PackageIcon>

<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Material.Avalonia/Material.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<PackageTags>avalonia xaml material design theme colour color ui ux material-design google-material</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>FavIcon.png</PackageIcon>

<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Material.Colors/Material.Colors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<Description>Color palette component of Material.Avalonia.</Description>

<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>

</Project>
13 changes: 12 additions & 1 deletion Material.Demo/Material.Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AvaloniaVersion>11.0.9</AvaloniaVersion>
<IsPackable>false</IsPackable>

<PublishAot>true</PublishAot>

<IsTrimmable>true</IsTrimmable>
<TrimMode>link</TrimMode>
<!--These can help when debugging weird exceptions especially when reflection is involved. See https://github.com/dotnet/corert/blob/master/Documentation/using-corert/optimizing-corert.md -->
<!--RootAllApplicationAssemblies: False -> TrimMode:link See https://github.com/dotnet/runtimelab/issues/597 and https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/optimizing.md -->
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
<IlcGenerateStackTraceData Condition="'$(Configuration.toUpper())' != 'DEBUG'">false</IlcGenerateStackTraceData>
<IlcDisableUnhandledExceptionExperience>true</IlcDisableUnhandledExceptionExperience>
<StripSymbols Condition="'$(Configuration.toUpper())' != 'DEBUG'">true</StripSymbols>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Material.Ripple/Material.Ripple.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<Description>Ripple component library of Material.Avalonia.</Description>

<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions Material.Styles/Material.Styles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<Description>Main styles library of Material.Avalonia.</Description>

<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
27 changes: 23 additions & 4 deletions Material.Styles/MaterialToolKit.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Avalonia;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.Styling;
using Material.Styles.Additional;
using Material.Styles.Assists.Mixins;

Expand All @@ -14,11 +15,29 @@ static MaterialToolKit() {
MaterialBorderBoxShadowMixin.Attach<Border>();
}


public MaterialToolKit() {
AvaloniaXamlLoader.Load(this);
if (AppContext.TryGetSwitch("MaterialThemeIncludeDataGrid", out var includeDataGrid) && includeDataGrid) {
Add(new StyleInclude((Uri?)null) { Source = new Uri("avares://Material.Avalonia.DataGrid/DataGrid.xaml") });
}
IncludeDataGridStyles();
}


#pragma warning disable IL2072

#if NET5_0_OR_GREATER
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, "MaterialDataGridStyles",
"Material.Avalonia.DataGrid")]
[UnconditionalSuppressMessage("Trimming",
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
Justification = "Referenced by DynamicDependency")]
#endif
private void IncludeDataGridStyles() {
if (!AppContext.TryGetSwitch("MaterialThemeIncludeDataGrid", out var includeDataGrid) ||
!includeDataGrid) return;
var dataGridStylesType = Assembly.Load("Material.Avalonia.DataGrid")
.GetType("Material.Avalonia.DataGrid.MaterialDataGridStyles")!;
var instance = Activator.CreateInstance(dataGridStylesType)!;
Add((Avalonia.Styling.Styles)instance);
}
}
}

0 comments on commit f00728c

Please sign in to comment.