Skip to content

Commit

Permalink
[Trimming] Enable trimming and AOT analyzers (#21505)
Browse files Browse the repository at this point in the history
* Enable analyzers wherever possible without any changes

* Change IsTrimmable to IsAotCompatible

* Windows Essentials are just Trimmable, not AOT compatible

* Avoid using non-generic Enum.GetValues on Tizen

* Ignore SingleFileAnalyzer warnings in BlazorWebView WPF and WinForms
  • Loading branch information
simonrozsival authored Apr 15, 2024
1 parent d22dece commit 59e0096
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorWebView/src/WindowsForms/BlazorWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ private void StartWebViewCoreIfPossible()
// We assume the host page is always in the root of the content directory, because it's
// unclear there's any other use case. We can add more options later if so.
string appRootDir;
#pragma warning disable IL3000 // 'System.Reflection.Assembly.Location.get' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.
var entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;
#pragma warning restore IL3000
if (!string.IsNullOrEmpty(entryAssemblyLocation))
{
appRootDir = Path.GetDirectoryName(entryAssemblyLocation)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorWebView/src/Wpf/BlazorWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ private void StartWebViewCoreIfPossible()
// We assume the host page is always in the root of the content directory, because it's
// unclear there's any other use case. We can add more options later if so.
string appRootDir;
#pragma warning disable IL3000 // 'System.Reflection.Assembly.Location.get' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.
var entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;
#pragma warning restore IL3000
if (!string.IsNullOrEmpty(entryAssemblyLocation))
{
appRootDir = Path.GetDirectoryName(entryAssemblyLocation)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Compatibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<iOSRoot>iOS\</iOSRoot>
<WindowsRoot>Windows\</WindowsRoot>
<TizenRoot>Tizen\</TizenRoot>
<IsTrimmable Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsTrimmable>
<IsAotCompatible Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsAotCompatible>
<MauiGenerateResourceDesigner>true</MauiGenerateResourceDesigner>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Tizen/ResourcePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static string GetPath(string res)
return res;
}

foreach (AppFW.ResourceManager.Category category in Enum.GetValues(typeof(AppFW.ResourceManager.Category)))
foreach (AppFW.ResourceManager.Category category in Enum.GetValues<AppFW.ResourceManager.Category>())
{
var path = AppFW.ResourceManager.TryGetPath(category, res);

Expand Down
5 changes: 5 additions & 0 deletions src/Controls/Foldable/src/Controls.Foldable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<NoWarn>$(NoWarn);CS1591</NoWarn>
<UseMaui Condition=" '$(UseWorkload)' == 'true' ">true</UseMaui>
</PropertyGroup>
<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>
<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>True</IsPackable>
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/Maps/src/Controls.Maps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>True</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static string GetPath(string res)
return res;
}

foreach (AppFW.ResourceManager.Category category in Enum.GetValues(typeof(AppFW.ResourceManager.Category)))
foreach (AppFW.ResourceManager.Category category in Enum.GetValues<AppFW.ResourceManager.Category>())
{
foreach (var file in new[] { res, res + ".jpg", res + ".png", res + ".gif" })
{
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/NuGet/Controls.NuGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down
6 changes: 6 additions & 0 deletions src/Core/maps/src/Maps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<NoWarn>$(NoWarn);CS1591;RS0041;RS0026;RS0027</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<Description>.NET MAUI Maps provides a map control for .NET MAUI apps. This only contains the core types. If you want the Map control, please install the Microsoft.Maui.Controls.Maps package.</Description>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<NoWarn>$(NoWarn);CS1591;RS0041;RS0026;RS0027</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netstandard2.1'">
<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
Expand Down
3 changes: 2 additions & 1 deletion src/Essentials/src/Essentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<RootNamespace>Microsoft.Maui.Essentials</RootNamespace>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<WarningsNotAsErrors>BI1234</WarningsNotAsErrors>
<IsTrimmable Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsTrimmable>
<IsAotCompatible Condition="!$(TargetFramework.StartsWith('netstandard')) and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">true</IsAotCompatible>
<IsTrimmable Condition="!$(TargetFramework.StartsWith('netstandard')) and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</IsTrimmable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);NU5104;RS0041;RS0026</NoWarn>
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors>
Expand Down
6 changes: 6 additions & 0 deletions src/Graphics/src/Graphics.Skia.WPF/Graphics.Skia.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<NoWarn>$(NoWarn);RS0041</NoWarn>
</PropertyGroup>

<PropertyGroup>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp.Views.WPF" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Graphics/src/Graphics.Skia/Graphics.Skia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<NoWarn>$(NoWarn);CS1591;RS0026;RS0027;RS0041</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down
6 changes: 6 additions & 0 deletions src/Graphics/src/Graphics.Win2D/Graphics.Win2D.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<DefineConstants>$(DefineConstants);MAUI_GRAPHICS_WIN2D</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down
6 changes: 6 additions & 0 deletions src/Graphics/src/Graphics/Graphics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<NoWarn>$(NoWarn);CS1591;RS0026;RS0027;RS0041</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="!$(TargetFramework.StartsWith('netstandard'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet package information -->
<IsPackable>true</IsPackable>
Expand Down

0 comments on commit 59e0096

Please sign in to comment.