Home > front end >  WPF and AOT: error NETSDK1168: WPF is not supported or recommended with trimming enabled
WPF and AOT: error NETSDK1168: WPF is not supported or recommended with trimming enabled

Time:11-11

I am trying to publish a WPF application (a blank application to try) with the AOT option, but I get this error: error NETSDK1168: WPF is not supported or recommended with trimming enabled.

In issues of the github, I have read that I can disabled the warnings setting in the project file the parameter <_SuppressWpfTrimError>true</_SuppressWpfTrimError>, but it is not available in my case.

I am using visual studio 2022, v17.4 and NET 7.

Is there some way to can use AOT with WPF?

Thanks.

CodePudding user response:

WPF is not supported and I wouldn't get my hopes up that it ever will be:

.NET 7 Preview 3 Is All About Native AOT

Native AOT is not for all projects, though, and Microsoft says in .NET 7 it will primarily help developers who build console apps or native libraries.

It's incredibly disappointing that it's not supported by WPF / Winforms (dunno about MAUI). That makes it only a console / library feature. That means I cannot use it in any of my larger applications but for those it only matters. I don't need startup improvement for tiny console projects.

We plan to look into expanding the scenarios where NativeAOT is a good fit over time. It's a function of time and resources. It is already possible to use WinForms with NativeAOT, but it requires some polish and won't be advertised as a supported scenario because of that. I suggest following a .NET community member who helped to make a lot of progress on this over the years: Andrey Kurdyumov -- https://twitter.com/Kurdiumov. Here's one of his articles where he made tweaks to various open source WinForms apps to make them compatible with NativeAOT in the form it is right now: https://codevision.medium.com/again-winforms-and-nativeaot-fd068425cc13. It can give you an idea where are we now.

  • Related