-
Notifications
You must be signed in to change notification settings - Fork 426
Failed to get rid of ML libraries in app build (Managed, Unpackaged, SingleFile) #5969
Description
Describe the bug
After upgrading from 1.7 to 1.8 I've encountered significant app distribution increase in size.
Digging into Release notes I've got that I need to use separate packages instead of new Metapackage.
My package references looks like this.
<PackageReference Include="Microsoft.WindowsAppSDK.Runtime" Version="1.8.251003001" />
<PackageReference Include="Microsoft.WindowsAppSDK.WinUI" Version="1.8.250906003" />But in output folder I get everything including ML libs:
onnxruntime.dll 21 MB
DirectML.dll 18 MB
Microsoft.Web.WebView2.Core.dll 800 kB
Which increases app size by ~40 MB in total compared to SDK v1.7. Btw, trimming doesn't help at all.
The exact package that installs ML libs is Microsoft.WindowsAppSDK.Runtime.
My app doesn't require neither ML nor WebView. How to install individual packages to make the app lighter? Or at least as it was in 1.7?
There's almost no difference in size between installing complete Microsoft.WindowsAppSDK Metapackage or two packages from xml code above. 1 MB lighter or so. Thus I've concluded that replacing Metapackage with individual packages doesn't works as expected for the simple desktop app.
Steps to reproduce the bug
- Create WinUI 3 project with v1.8 SDK
- Replace Metapackage with two packages from XML above
- Build Managed+Unpackaged
Expected behavior
There's no WebView2 or ML libraries in build output folder.
Screenshots
No response
NuGet package version
1.8.251003001
Packaging type
Unpackaged
Windows version
Windows 11 (26100.6899)
IDE
VS 2022
Additional context
Full .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<RootNamespace>Installer</RootNamespace>
<AssemblyName>MyInstallerApp</AssemblyName>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x64</Platforms>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<Nullable>enable</Nullable>
<WindowsPackageType>None</WindowsPackageType>
<ApplicationIcon>icon.ico</ApplicationIcon>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<SelfContained>true</SelfContained>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
<OptimizationPreference>Size</OptimizationPreference>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<IsAotCompatible>true</IsAotCompatible>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>
<ItemGroup>
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.8" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.6901" />
<PackageReference Include="Microsoft.WindowsAppSDK.Runtime" Version="1.8.251003001" />
<PackageReference Include="Microsoft.WindowsAppSDK.WinUI" Version="1.8.250906003" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Resource Include="icon.ico">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<None Update="icon.ico">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
<!-- Publish Properties -->
<PropertyGroup>
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
</PropertyGroup>
</Project>Workaround
Rollback SDK to 1.7.251014001, delete /bin and /obj folders in the project directory and Rebuild