C
C#2y ago
djibouti

✅ WPF Build size triples after changing target framework to net6.0-windows10.0.17763.0

Hello. My WPF application uses .net6 and recently I was asked to use 'toast' style Windows 10/11 notifications. Easy enough - I installed Microsoft.Toolkit.Uwp.Notifications and am using the ToastContentBuilder. However, in order to use the Show() method on the toast it requires changing the Target Framework from .net6.0-windows to net6.0-windows10.0.17763.0. It seemed simple enough but after doing a build I noticed my application size tripled to 34MB. I really would like to get it closer to my previous 11MB. Digging in I can see why. Simply by changing the Target framework it's now including Microsoft.Windows.SDK.NET.dll in the build which is 23MB in size. My question here is if there's a way for us to retain notification functionality without needing the large SDK dll? Are there any strategies to avoid this? Possibly by not changing the target framework but still leveraging the toast notification? I have no idea. Really appreciate any help here. Take care!
28 Replies
Angius
Angius2y ago
Did you maybe enable self-contained release? That bundles the entire .NET framework with your app
MODiX
MODiX2y ago
See $singlefile
Angius
Angius2y ago
$singlefile
MODiX
MODiX2y ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -r|--runtime implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file https://docs.microsoft.com/en-us/dotnet/core/rid-catalog https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish
Create a single file for application deployment - .NET
Learn what single file application is and why you should consider using this application deployment model.
.NET Runtime Identifier (RID) catalog
Learn about the Runtime Identifier (RID) and how RIDs are used in .NET.
djibouti
djiboutiOP2y ago
No it's set to False. I'm already doing a single file, but to see which file was taking 20+MB I disabled that temporarily. So I know it's the Microsoft.Windows.SDK.NET.dll lib cuz that wasn't previously in my build and it's 23MB My single file build is 11MB with <TargetFramework>.net6.0-windows</TargetFramework> and if I change the TFW to <TargetFramework>.net6.0-windows10.0.17763.0</TargetFramework> then Microsoft.Windows.SDK.NET.dll is included and the build size increases by 23MB.
ero
ero2y ago
what about trimming?
djibouti
djiboutiOP2y ago
Trimming support is disabled in .net6 unfortunately
Trinitek
Trinitek2y ago
is this a packaged app? I recall reading about this a few weeks ago, I don't think you need to use that package, you could just call the COM APIs directly no nevermind, that still requires you to enable the SDK
djibouti
djiboutiOP2y ago
Thanks for the response. I'm not sure what you mean about packaged app. My auto updating logic is centered on it being a single file so each update would contain the sdk, I'm hoping to avoid that
Trinitek
Trinitek2y ago
a lot of new Windows 10 APIs require you to have a "package identity" that is granted by MSIX doesn't apply here though
djibouti
djiboutiOP2y ago
I see It seems like I'm just going to have to decide if updates are now 30+mb to include the sdk or dropping toast notifications Weird how offline web apps can hook into the API so cheaply but a desktop app can't I suppose the browser is responsible for that though
Trinitek
Trinitek2y ago
one thing you could look into is showing a notification Win7-style, with an icon in the notification area on 7, those notifications will appear as balloons, but on 10 and 11 they appear like any other toast notification
Trinitek
Trinitek2y ago
Notifications and the Notification Area - Win32 apps
The notification area is a portion of the taskbar that provides a temporary source for notifications and status.
Starlk
Starlk2y ago
Have you thought of using UWP? (instead of WPF) if small binary size matters that much then UWP is pretty much the go to
djibouti
djiboutiOP2y ago
I'll try that out! I haven't. Maybe I should look into it. I was worried about working in a new framework. I think I also determined my use case might not fit. This application needs admin permissions at times and my installer runs several other installers at the same time (exe). It's an app for connecting to our app infrastructure and requires a few dependencies
Trinitek
Trinitek2y ago
sounds like that rules out UWP then
Starlk
Starlk2y ago
yeah I'm quite certain that you still can do it with UWP but due to how UWP was designed it might be harder
Angius
Angius2y ago
UWP is pretty sandboxed
djibouti
djiboutiOP2y ago
I think the only hangup really was the installation of uwp app required msix or something like that.
Starlk
Starlk2y ago
MSIX is fine
djibouti
djiboutiOP2y ago
And msix doesn't like you installing a bunch of apps that require admin rights. (Rightfully so)
Starlk
Starlk2y ago
you can ask for full trust
djibouti
djiboutiOP2y ago
Ah ok. Didn't realize I will look into the win7 style
djibouti
djiboutiOP2y ago
djibouti
djiboutiOP2y ago
I think this is a good alternative to including the whole Windows SDK just for toast notifications. I lose some functionality - like arguments / responses and setting my own custom image/icons. But shaving 2/3 off the build size seems like a good compromise. I appreciate all the help here.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
djibouti
djiboutiOP2y ago
/close
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity. Closed!
Want results from more Discord servers?
Add your server