dotnet / reactive

The Reactive Extensions for .NET
http://reactivex.io
MIT License
6.71k stars 750 forks source link

Adding System.Reactive to WinUI3/MAUI app increases package size by 44MB because it includes WPF and WinForms references #1745

Open DeanFaizal opened 2 years ago

DeanFaizal commented 2 years ago

Bug

Which library version? System.Reactive 5.0.0

What are the platform(s), environment(s) and related component version(s)? WinUI3, MAUI

What is the use case or problem? Using System.Reactive in WinUI3 app

What is the expected outcome? Only required references for the platform are included in app package

What is the actual outcome? The app package increases from 44MB to 88MB with the following additional dlls in the package:


"Accessibility.dll"
"D3DCompiler_47_cor3.dll"
"DirectWriteForwarder.dll"
"Microsoft.VisualBasic.Forms.dll"
"Microsoft.Win32.Registry.AccessControl.dll"
"Microsoft.Win32.SystemEvents.dll"
"PenImc_cor3.dll"
"PresentationCore.dll"
"PresentationFramework.Aero.dll"
"PresentationFramework.Aero2.dll"
"PresentationFramework.AeroLite.dll"
"PresentationFramework.Classic.dll"
"PresentationFramework.dll"
"PresentationFramework.Luna.dll"
"PresentationFramework.Royale.dll"
"PresentationFramework-SystemCore.dll"
"PresentationFramework-SystemData.dll"
"PresentationFramework-SystemDrawing.dll"
"PresentationFramework-SystemXml.dll"
"PresentationFramework-SystemXmlLinq.dll"
"PresentationNative_cor3.dll"
"PresentationUI.dll"
"ReachFramework.dll"
"System.CodeDom.dll"
"System.Configuration.ConfigurationManager.dll"
"System.Design.dll"
"System.Diagnostics.EventLog.dll"
"System.Diagnostics.PerformanceCounter.dll"
"System.DirectoryServices.dll"
"System.Drawing.Common.dll"
"System.Drawing.Design.dll"
"System.IO.Packaging.dll"
"System.Printing.dll"
"System.Reactive.dll"
"System.Resources.Extensions.dll"
"System.Security.Cryptography.Pkcs.dll"
"System.Security.Cryptography.ProtectedData.dll"
"System.Security.Cryptography.Xml.dll"
"System.Security.Permissions.dll"
"System.Threading.AccessControl.dll"
"System.Windows.Controls.Ribbon.dll"
"System.Windows.Extensions.dll"
"System.Windows.Forms.Design.dll"
"System.Windows.Forms.Design.Editors.dll"
"System.Windows.Forms.dll"
"System.Windows.Forms.Primitives.dll"
"System.Windows.Input.Manipulations.dll"
"System.Windows.Presentation.dll"
"System.Xaml.dll"
"UIAutomationClient.dll"
"UIAutomationClientSideProviders.dll"
"UIAutomationProvider.dll"
"UIAutomationTypes.dll"
"vcruntime140_cor3.dll"
"WindowsFormsIntegration.dll"
"wpfgfx_cor3.dll"

These seem to be localization folders: "cs" "de" "es" "fr" "it" "ja" "ko" "pl" "pt-BR" "ru" "tr" "zh-Hans" "zh-Hant"

Inside each localization folder: "System.Windows.Input.Manipulations.resources.dll" "System.Xaml.resources.dll" "UIAutomationClient.resources.dll" "UIAutomationClientSideProviders.resources.dll" "UIAutomationProvider.resources.dll" "UIAutomationTypes.resources.dll" "WindowsBase.resources.dll" "WindowsFormsIntegration.resources.dll" "Microsoft.VisualBasic.Forms.resources.dll" "PresentationCore.resources.dll" "PresentationFramework.resources.dll" "PresentationUI.resources.dll" "ReachFramework.resources.dll" "System.Windows.Controls.Ribbon.resources.dll" "System.Windows.Forms.Design.resources.dll" "System.Windows.Forms.Primitives.resources.dll" "System.Windows.Forms.resources.dll"


> What is the stacktrace of the exception(s) if any?
N/A

> Do you have a code snippet or project that reproduces the problem?

1. Create a File > New MAUI app
2. Update OnCounterClicked
private void OnCounterClicked(object sender, EventArgs e)
{
    var source = Observable.Timer(DateTimeOffset.MinValue, TimeSpan.FromSeconds(1)).Timestamp();
    source.Subscribe(x =>
    Application.Current.Dispatcher.Dispatch(() =>
    {
        CounterLabel.Text = x.Timestamp.ToString();
    }));
    SemanticScreenReader.Announce(CounterLabel.Text);
}
3. Add System.Reactive nuget or the following in csproj:
<ItemGroup>
  <PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>
4. Build the app in command prompt

msbuild MauiReactive.sln -restore -p:Configuration=Release

5. Package the app in command prompt

"C:\Program Files (x86)\Windows Kits\10\App Certification Kit\MakeAppx" pack /v /h SHA256 /d "MauiReactive\bin\Release\net6.0-windows10.0.19041\win10-x64" /p MauiReactive.msix

DeanFaizal commented 2 years ago

This seems to be the root cause: https://github.com/dotnet/reactive/blob/main/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj#L14-L15

idg10 commented 9 months ago

As a workaround, does adding this to the csproj for your main application resolve the problem?

  <PropertyGroup>
    <DisableTransitiveFrameworkReferences>true</DisableTransitiveFrameworkReferences>
    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>false</UseWPF>
  </PropertyGroup>