Skip to content

Commit

Permalink
Merge pull request #6 from maxkatz6/aot-compatibility
Browse files Browse the repository at this point in the history
Adjust/avoid AOT compatibility warnings/errors
  • Loading branch information
wieslawsoltes authored Oct 25, 2024
2 parents 501da78 + 16c2d41 commit 4c2f305
Show file tree
Hide file tree
Showing 54 changed files with 117 additions and 104 deletions.
1 change: 1 addition & 0 deletions AvaloniaBehaviors.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "props", "props", "{40A43022
build\SignAssembly.props = build\SignAssembly.props
build\SourceLink.props = build\SourceLink.props
build\XUnit.props = build\XUnit.props
build\TrimmingEnable.targets = build\TrimmingEnable.targets
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{721A55B7-C5B0-44E2-803A-56E291C672FE}"
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Copyright>Copyright © Wiesław Šoltés 2024</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/wieslawsoltes/AvaloniaBehaviors</PackageProjectUrl>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<PropertyGroup>
<AnalysisLevel>latest</AnalysisLevel>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageVersion Include="Avalonia.Headless.XUnit" Version="$(AvaloniaVersion)" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
<PackageVersion Include="Nuke.Common" Version="5.3.0" />
</ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions build/TrimmingEnable.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) AND '$(IsTrimmable)' != 'false'">
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible Condition="'$(IsAotCompatible)' == ''">true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) AND '$(ILLinkTreatWarningsAsErrors)' != 'false'">
<ILLinkTreatWarningsAsErrors Condition="'$(ILLinkTreatWarningsAsErrors)' == ''">true</ILLinkTreatWarningsAsErrors>
<!-- Trim warnings -->
<WarningsAsErrors>$(WarningsAsErrors);IL2000;IL2001;IL2002;IL2003;IL2004;IL2005;IL2006;IL2007;IL2008;IL2009;IL2010;IL2011;IL2012;IL2013;IL2014;IL2015;IL2016;IL2017;IL2018;IL2019;IL2020;IL2021;IL2022;IL2023;IL2024;IL2025;IL2026;IL2027;IL2028;IL2029;IL2030;IL2031;IL2032;IL2033;IL2034;IL2035;IL2036;IL2037;IL2038;IL2039;IL2040;IL2041;IL2042;IL2043;IL2044;IL2045;IL2046;IL2047;IL2048;IL2049;IL2050;IL2051;IL2052;IL2053;IL2054;IL2055;IL2056;IL2057;IL2058;IL2059;IL2060;IL2061;IL2062;IL2063;IL2064;IL2065;IL2066;IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091;IL2092;IL2093;IL2094;IL2095;IL2096;IL2097;IL2098;IL2099;IL2100;IL2101;IL2102;IL2103;IL2104;IL2105;IL2106;IL2107;IL2108;IL2109;IL2110;IL2111;IL2112;IL2113;IL2114;IL2115;IL2116;IL2117;IL2118;IL2119;IL2120;IL2121;IL2122;IL2123;IL2124;IL2125;IL2126;IL2127;IL2128;IL2129;IL2130;IL2131;IL2132;IL2133;IL2134;IL2135;IL2136;IL2137;IL2138;IL2139;IL2140;IL2141;IL2142;IL2143;IL2144;IL2145;IL2146;IL2147;IL2148;IL2149;IL2150;IL2151;IL2152;IL2153;IL2154;IL2155;IL2156;IL2157</WarningsAsErrors>
<!-- NativeAOT warnings -->
<WarningsAsErrors Condition="'$(IsAotCompatible)' == 'true'">$(WarningsAsErrors);IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) AND '$(EnableRuntimeMarshalling)' != 'true'">
<WarningsAsErrors>$(WarningsAsErrors);CA1420;CA1421</WarningsAsErrors>
</PropertyGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) AND '$(EnableRuntimeMarshalling)' != 'true'">
<AssemblyAttribute Include="System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Diagnostics" />
<PackageReference Include="Avalonia.Diagnostics" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Avalonia.Fonts.Inter" />
<PackageReference Include="Avalonia.ReactiveUI" />
</ItemGroup>

<ItemGroup>
<!-- This project contains several pages using reflection based behaviors/actions. Make sure all sample types are preserved. -->
<TrimmerRootAssembly Include="BehaviorsTestApplication" />
<!-- It's necessary, so reflection based behaviors/actions can access Avalonia members. Such as Button.Click. -->
<TrimmerRootAssembly Include="Avalonia.Base" />
<TrimmerRootAssembly Include="Avalonia.Controls" />
</ItemGroup>
<!--<Import Project="..\..\build\SignAssembly.props" />-->

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions samples/BehaviorsTestApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static AppBuilder BuildAvaloniaApp()
GC.KeepAlive(typeof(Interaction).Assembly);
GC.KeepAlive(typeof(ComparisonConditionType).Assembly);
return AppBuilder.Configure<App>()
.WithInterFont()
.UsePlatformDetect()
.UseReactiveUI()
.LogToTrace();
Expand Down
5 changes: 2 additions & 3 deletions samples/BehaviorsTestApplication/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700"
FontFamily="avares://Avalonia.Fonts.Inter/Assets#Inter">
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700">
<UserControl.Styles>
<Style Selector="TabItem">
<Setter Property="FontSize" Value="16" />
Expand Down
6 changes: 0 additions & 6 deletions samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,5 @@ public MainWindow()
{
InitializeComponent();
DataContext = new MainWindowViewModel();
this.AttachDevTools();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
xmlns:vm="clr-namespace:BehaviorsTestApplication.ViewModels"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"
x:DataType="vm:MainWindowViewModel">
<Grid RowDefinitions="*,Auto" ColumnDefinitions="30*,5,30*,5,30*">
<Canvas Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5"
Margin="5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</Style>
</TreeView.Styles>
<TreeView.ItemTemplate>
<TreeDataTemplate DataType="vm:ItemViewModel" x:CompileBindings="False"
<TreeDataTemplate DataType="vm:ItemViewModel"
ItemsSource="{Binding Items}">
<controls:EditableItem Text="{Binding Value}" />
</TreeDataTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
xmlns:reactive="using:System.Reactive"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
5 changes: 0 additions & 5 deletions samples/DragAndDropSample/App.axaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DragAndDropSample"
x:Class="DragAndDropSample.App"
Name="DragAndDropSample"
RequestedThemeVariant="Light">
<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
Expand Down
3 changes: 2 additions & 1 deletion samples/DragAndDropSample/DragAndDropSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,7 +17,7 @@
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Controls.DataGrid" />
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Diagnostics" />
<PackageReference Include="Avalonia.Diagnostics" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Avalonia.Fonts.Inter" />
<PackageReference Include="Avalonia.ReactiveUI" />
Expand Down
29 changes: 0 additions & 29 deletions samples/DragAndDropSample/ViewLocator.cs

This file was deleted.

3 changes: 2 additions & 1 deletion samples/DragAndDropSample/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
x:Class="DragAndDropSample.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Width="650" WindowStartupLocation="CenterScreen"
Title="DragAndDropSample">
Title="DragAndDropSample"
x:DataType="vm:MainWindowViewModel">

<Design.DataContext>
<vm:MainWindowViewModel />
Expand Down
3 changes: 2 additions & 1 deletion samples/DraggableDemo/DraggableDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Diagnostics" />
<PackageReference Include="Avalonia.Diagnostics" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Avalonia.Fonts.Inter" />
<PackageReference Include="Avalonia.ReactiveUI" />
Expand Down
2 changes: 1 addition & 1 deletion samples/DraggableDemo/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:models="clr-namespace:DraggableDemo.Models"
mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="550"
x:Class="DraggableDemo.MainWindow"
x:CompileBindings="True" x:DataType="local:MainWindow"
x:DataType="local:MainWindow"
WindowState="Normal" WindowStartupLocation="CenterScreen"
Width="1200" Height="550"
Title="Draggable Controls Demo">
Expand Down
1 change: 1 addition & 0 deletions src/Avalonia.Xaml.Behaviors/Avalonia.Xaml.Behaviors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<Import Project="..\..\build\SignAssembly.props" />
<Import Project="..\..\build\SourceLink.props" />
<Import Project="..\..\build\TrimmingEnable.targets" />

<ItemGroup>
<ProjectReference Include="..\Avalonia.Xaml.Interactivity\Avalonia.Xaml.Interactivity.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// <summary>
/// An action that will change a specified Avalonia property to a specified value when invoked.
/// </summary>
[RequiresUnreferencedCode("This functionality is not compatible with trimming.")]
public class ChangeAvaloniaPropertyAction : Avalonia.Xaml.Interactivity.Action
{
/// <summary>
Expand Down Expand Up @@ -82,7 +83,6 @@ public override object Execute(object? sender, object? parameter)
return false;
}

[RequiresUnreferencedCode("This functionality is not compatible with trimming.")]
private void UpdateAvaloniaPropertyValue(AvaloniaObject targetObject, AvaloniaProperty targetProperty)
{
ValidateTargetProperty(targetProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<Import Project="..\..\build\SignAssembly.props" />
<Import Project="..\..\build\SourceLink.props" />
<Import Project="..\..\build\TrimmingEnable.targets" />

<ItemGroup>
<ProjectReference Include="..\Avalonia.Xaml.Interactivity\Avalonia.Xaml.Interactivity.csproj" />
Expand Down
Loading

0 comments on commit 4c2f305

Please sign in to comment.