{"id":769,"date":"2024-09-11T08:01:13","date_gmt":"2024-09-11T15:01:13","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/?p=769"},"modified":"2025-11-25T16:06:54","modified_gmt":"2025-11-26T00:06:54","slug":"preview-uwp-support-for-dotnet-9-native-aot","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/preview-uwp-support-for-dotnet-9-native-aot\/","title":{"rendered":"Modernize your UWP app with preview UWP support for .NET 9 and Native AOT"},"content":{"rendered":"<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Important<\/strong><\/p>UWP support for modern .NET is now generally available, and no preview tooling is required anymore. Visual Studio 2022 includes built-in project templates to create new UWP applications, class libraries, and Windows Runtime components using .NET 9. Visual Studio 2026 includes updated versions of all new templates targeting .NET 10. The Windows SDK with support for UWP XAML projects with modern .NET is also included in both editions of Visual Studio. The original blog post can be viewed below, however the steps and instructions to try things out before the official release are not applicable anymore, as everything will now just work out of the box.<\/div><\/p>\n<p>We\u2019re introducing the <strong>initial preview UWP (Universal Windows\nPlatform) support for .NET 9<\/strong>, providing a path for existing UWP\ndevelopers to modernize their apps with the latest .NET and Native\nAOT.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/hero-image.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-770\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/hero-image.png\" alt=\"Preview UWP support for .NET 9\" width=\"1454\" height=\"817\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/hero-image.png 1454w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/hero-image-300x169.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/hero-image-1024x575.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/hero-image-768x432.png 768w\" sizes=\"(max-width: 1454px) 100vw, 1454px\" \/><\/a><\/p>\n<p>Are you a UWP app developer considering migrating to Windows App SDK\nand WinUI 3? Or wanting to leverage the latest releases of .NET and\nNative AOT? Or perhaps you\u2019ve been struggling with referencing new\nversions of your favorite libraries, because they only include support\nfor .NET 6 and above? Well, look no further! This <strong>preview UWP\nsupport for .NET 9<\/strong> provides a path for UWP apps to modernize\nusing the latest version of .NET.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>UWP support for .NET 9 is\navailable in preview, and as such you should expect to potentially find\nissues, as well as missing functionality (such as no XAML Designer at\nthe moment). You should also expect some binary size regressions\ncompared to .NET Native (more on this below). This first public preview\nis only the first step in this journey for UWP apps to adopt the latest\nversion of .NET, and we\u2019re looking forward to your feedback (see <a href=\"#summary9\">#summary<\/a> for support contacts) as we work on\nimproving the tooling and the developer experience to make it as good as\npossible.<\/div><\/p>\n<h2 id=\"what-is-the-uwp-support-for-.net-9\">What is the UWP support for\n.NET 9<\/h2>\n<p>This preview is a set of updated tools and components that are part\nof .NET, Visual Studio, the Windows SDK, and more, to allow using the\nlatest version of .NET and C# for building UWP apps. This preview\n<strong>does not introduce any new features for UWP<\/strong>. Instead,\nit provides a migration path for developers to modernize their apps with\n.NET 9 while they consider moving toward WinUI 3. It is rather a way for\nUWP app developers to modernize their apps and leverage all the recent\nadvancements in .NET and C#, while still retaining the existing features\nthat UWP provides today.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>If you are starting to develop new\nWindows apps, we recommend you consider using the <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/windows-app-sdk\/\">Windows\nApp SDK<\/a> and <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/develop\/\">WinUI 3<\/a>\nrather than UWP. Although still officially supported, UWP is not under\nactive development. You can refer to <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/get-started\/start-here\">Start\ndeveloping Windows apps<\/a> for more information. If you\u2019d like to keep\nleveraging AppContainer (see <a href=\"#glossary9\">#glossary<\/a>) for\nextra security, just like UWP, refer to <a href=\"https:\/\/learn.microsoft.com\/windows\/msix\/msix-container\">MSIX\nAppContainer apps<\/a> to see how you can configure your WinUI 3 app to\nbe a partial trust Windows app.<\/div><\/p>\n<p>The main goals of the UWP support for .NET 9 are as follows:<\/p>\n<ul>\n<li><strong>Providing a better migration path for UWP developers wanting\nto migrate to WinUI 3<\/strong>. Rather than having to perform the entire\nmigration in a single step (meaning both updating all the .NET runtime\nas well as the entire UI framework and app model), the UWP support for\n.NET 9 provides an incremental path towards WinUI 3. By allowing you to\nfocus on upgrading the .NET runtime, separate from the UI framework and\napp model, and adopting advances in .NET to modernize your codebase, you\ncan now split the migration into two \u201ccheckpoints\u201d. First, move to .NET\n9, and get the app working under Native AOT (which can already require\nsignificant work depending on the scenarios). Then, after making sure\nthat this first part of the migration is successful, you can focus on\nswitching from UWP XAML to WinUI 3, and to the Win32 app model. Using\nthis approach makes the migration more incremental, and less risky. This\nis also the approach that we are taking with the <strong>Microsoft\nStore<\/strong>: we are currently working on migrating to .NET 9, and we\nplan on shipping a new version of the app running on Native AOT in the\nnear future.<\/li>\n<li><strong>Enabling developers to remove dependencies on .NET Native,\nso they can benefit from the latest .NET and C# features, no matter what\ntheir app model is<\/strong>. If you are currently targeting UWP because\nyou can\u2019t migrate to Windows App SDK and WinUI 3 for some reason (maybe\nbecause Windows App SDK doesn\u2019t support some critical APIs, or because\nyou don\u2019t have resources to do a full migration yet), we still want to\nallow you to get up to par with all other Windows UI frameworks. This\nupdate reduces the friction UWP developers experience when attempting to\nmodernize legacy apps using older libraries from the ecosystem.\nAdditionally, it will allow you to stop using <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/dotnet-native\/\">.NET\nNative<\/a>, which on top of being limited to more or less the .NET Core\n2.0 feature level (and just <a href=\"https:\/\/learn.microsoft.com\/dotnet\/standard\/net-standard?tabs=net-standard-2-0\">.NET\nStandard 2.0<\/a> for shared class libraries), has extremely slow build\ntimes, poor debugging support for issues related to trimming and AOT\ncompatibility, and is only receiving security updates.<\/li>\n<\/ul>\n<p>Whether you\u2019re migrating from UWP to WinUI 3, or you\u2019re just trying\nto be more productive on your app\u2019s existing UI framework, this preview\nlets you modernize to the latest .NET and C# and take advantage of\nrecent tooling improvements to ease your migration journey.<\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Tip<\/strong><\/p>If you\u2019re not familiar with\nall the exact terminology around UWP and all related technologies, or if\nyou\u2019d simply like to learn more, you can refer to the <a href=\"#glossary9\">#glossary<\/a> section at the end of this blog post.\nThis glossary provides all the context you might need to fully\nunderstand where the UWP support for .NET 9 ties into the Windows\nplatform.<\/div><\/p>\n<h2 id=\"how-to-get-started\">How to get started<\/h2>\n<p>In order to try out the UWP support for .NET 9, a few preview tools\nare needed. Here\u2019s everything you\u2019ll need to install.<\/p>\n<p>First, make sure to get Visual Studio 2022 17.12 Preview 2, which\nwent live just yesterday! All new tooling is included in the \u201cUniversal\nWindows Platform tools\u201d section under the \u201cWindows application\ndevelopment\u201d workload. To install all the necessary components, follow\nthese easy steps:<\/p>\n<ul>\n<li>Open the Visual Studio Installer.<\/li>\n<li>Under \u201cWorkloads\u201d &gt; \u201cDesktop &amp; Mobile\u201d, select the \u201cWindows\napplication development\u201d workload.<\/li>\n<li>Under \u201cOptional\u201d (in the right pane), select:\n<ul>\n<li>\u201cUniversal Windows Platform tools\u201d, which contains all tooling for\nUWP apps<\/li>\n<li>\u201cWindows 11 SDK (10.0.26100.0)\u201d, needed to build UWP XAML apps<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer.png\"><img decoding=\"async\" class=\"alignnone wp-image-774 size-full\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer.png\" alt=\"The Visual Studio Installer, with the UWP components selected to install all necessary tooling to leverage the UWP support for .NET 9\" width=\"2104\" height=\"1240\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer.png 2104w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer-300x177.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer-1024x603.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer-768x453.png 768w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer-1536x905.png 1536w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-installer-2048x1207.png 2048w\" sizes=\"(max-width: 2104px) 100vw, 2104px\" \/><\/a><\/p>\n<p>You\u2019ll also need an updated version of the XAML compiler that\nsupports .NET 9 projects. This will be included in an upcoming servicing\nrelease of the Windows 11 SDK (10.0.26100.0). However, if you want to\ntry things out today, we have a small bundle with just the updated XAML\ncompiler, which you can manually patch on your machine. To do that, <a href=\"https:\/\/aka.ms\/preview-uwp-support-for-dotnet9-windows-sdk\">download\nthe preview Windows SDK bundle<\/a> and follow the instructions in the\nREADME file.<\/p>\n<p>Next, you\u2019ll need to install the latest nightly build of the .NET\nSDK, which you can download from the <a href=\"https:\/\/github.com\/dotnet\/sdk\">.NET SDK GitHub repo<\/a>. These changes\nwill also be available in .NET 9 RC2, once it releases later this year. For the time being, you\u2019ll\nfind the download link for .NET 9 nightly builds in the <a href=\"https:\/\/github.com\/dotnet\/sdk\/blob\/main\/documentation\/package-table.md\">latest\nbuilds table<\/a> page. Don\u2019t forget to follow the instructions in the\nREADME to also add the necessary preview NuGet feed for .NET 9 packages.\nIn order to avoid installing nightly .NET SDK builds machine-wide, you\ncan pick the .zip option of the .NET SDK instead of the installer. Then,\nextract it in a folder of your choosing (we recommend excluding the\nfolder from Windows Defender for extra build performance or setting up a\n<a href=\"https:\/\/learn.microsoft.com\/windows\/dev-drive\/\">DevDrive<\/a>),\nand add it to PATH. This is a convenient way to try out nightly builds\nwithout having to worry about uninstalling them later on.<\/p>\n<p>For further convenience, below is the contents of a complete <a href=\"https:\/\/learn.microsoft.com\/nuget\/reference\/nuget-config-file\">nuget.config<\/a>\nfile you can copy-paste next to your .sln file that includes the .NET 9\nfeed. This will ensure that UWP .NET projects using the latest nightly\nbuild of the .NET 9 SDK from the .NET SDK repo will be able to correctly\nrestore all their dependent NuGet packages:<\/p>\n<div id=\"cb1\" class=\"sourceCode\">\n<pre class=\"sourceCode xml\"><code class=\"sourceCode xml\"><span id=\"cb1-1\"><span class=\"fu\">&lt;?xml<\/span><span class=\"ot\"> version=<\/span><span class=\"st\">\"1.0\"<\/span><span class=\"ot\"> encoding=<\/span><span class=\"st\">\"utf-8\"<\/span><span class=\"fu\">?&gt;<\/span><\/span>\r\n<span id=\"cb1-2\">&lt;<span class=\"kw\">configuration<\/span>&gt;<\/span>\r\n<span id=\"cb1-3\">  &lt;<span class=\"kw\">packageSources<\/span>&gt;<\/span>\r\n<span id=\"cb1-4\">    &lt;<span class=\"kw\">clear<\/span> \/&gt;<\/span>\r\n<span id=\"cb1-5\">    &lt;<span class=\"kw\">add<\/span><span class=\"ot\"> key=<\/span><span class=\"st\">\"nuget\"<\/span><span class=\"ot\"> value=<\/span><span class=\"st\">\"https:\/\/api.nuget.org\/v3\/index.json\"<\/span> \/&gt;<\/span>\r\n<span id=\"cb1-6\">    &lt;<span class=\"kw\">add<\/span><span class=\"ot\"> key=<\/span><span class=\"st\">\"dotnet9\"<\/span><span class=\"ot\"> value=<\/span><span class=\"st\">\"https:\/\/pkgs.dev.azure.com\/dnceng\/public\/_packaging\/dotnet9\/nuget\/v3\/index.json\"<\/span> \/&gt;<\/span>\r\n<span id=\"cb1-7\">  &lt;\/<span class=\"kw\">packageSources<\/span>&gt;<\/span>\r\n<span id=\"cb1-8\">&lt;\/<span class=\"kw\">configuration<\/span>&gt;<\/span><\/code><\/pre>\n<\/div>\n<p>As part of the UWP support for .NET 9, we now also have new project\ntemplates for UWP apps and libraries. To get started, install <a href=\"https:\/\/aka.ms\/preview-uwp-support-for-dotnet9-templates-vsix\">this\nVSIX<\/a> to get all the new templates (in preview), which we\u2019ll be using\nin the guide below as well to show how to create a new UWP project with .NET 9 support.<\/p>\n<p>And that\u2019s it! All other changes across other components are included\nor referenced by default. Now that all preview tools are installed, we\ncan actually start creating our first UWP .NET 9 project, or start\nmigrating our existing UWP applications to the latest .NET and C#.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>This preview should be seen as an\nincremental migration step, with the ultimate goal of moving toward\nWinUI 3 for the most up-to-date and actively supported\nframework.<\/div><\/p>\n<h2 id=\"creating-a-uwp-.net-9-project\">Creating a UWP .NET 9\nproject<\/h2>\n<p>After installing the VSIX we linked above, the new templates should\nshow up automatically when opening Visual Studio, or you can also easily\nfilter all templates by searching for \u201cUWP\u201d. These templates are meant\nto be a convenient way to create updated UWP apps, libraries, runtime\ncomponents, and more, targeting .NET 9, both to help migrating existing\napps, as well as for developers wanting to experiment with new project\nideas.<\/p>\n<p>To see all these new templates, launch Visual Studio and click\n\u201cCreate a new project\u201d:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates.png\"><img decoding=\"async\" class=\"alignnone wp-image-775 size-full\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates.png\" alt=\"The new project templates for UWP apps using .NET 9, initially provided through a VSIX installer as part of the preview UWP support for .NET 9\" width=\"1706\" height=\"1173\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates.png 1706w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates-300x206.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates-1024x704.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates-768x528.png 768w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/vs-templates-1536x1056.png 1536w\" sizes=\"(max-width: 1706px) 100vw, 1706px\" \/><\/a><\/p>\n<p>We included 5 new project templates:<\/p>\n<ul>\n<li><strong>Blank UWP App (Preview for .NET 9)<\/strong>: this is a\nclassic UWP XAML applications, and the most popular UWP project\ntemplate. If you\u2019re not sure where to start, click on this project\ntemplate. Just like the original project template for UWP, it includes\nsome basic setup with a root <a href=\"https:\/\/learn.microsoft.com\/uwp\/api\/windows.ui.xaml.controls.frame\"><code>Frame<\/code><\/a>,\na <code>MainPage<\/code> that is navigated to, and minimal sample XAML\ncontent. This project template also features single-project MSIX\nsupport, just like WinUI 3 applications (and just like classic UWP\ndoes). This ensures a smooth migration path from classic UWP to WinUI 3\nas well.<\/li>\n<li><strong>Blank UWP CoreApplication App (Preview for .NET 9)<\/strong>:\nthis is a brand new template, that was previously only available for UWP\nC++ applications. This is meant for more advanced scenarios, and it\nallows creating apps with purely Composition\/DirectX content, with no\nXAML whatsoever! It\u2019s also perfect for experimenting with Win2D and\ngraphics APIs.<\/li>\n<li><strong>UWP Windows Runtime Component (Preview for .NET 9)<\/strong>:\na managed WinRT component, using latest the latest versions of .NET and\nCsWinRT. It can be used on its own to create reusable software\ncomponents that can be shared across applications, or to implement UWP\nfunctionality that requires WinRT component activation. For instance,\nyou can use this template to implement <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/launch-resume\/support-your-app-with-background-tasks\">out-of-process\nUWP background tasks<\/a> or <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/audio-video-camera\/custom-video-effects\">custom\nvideo effects<\/a>.<\/li>\n<li><strong>UWP Class Library (Preview for .NET 9)<\/strong>: a UWP class\nlibrary using latest .NET and C#, with XAML support.<\/li>\n<li><strong>Blank UWP App with Windows Application Packaging Project\n(Preview for .NET 9)<\/strong>: this project is equivalent to the first\none, except that rather than leveraging single-project MSIX packaging,\nit uses a separate <a href=\"https:\/\/learn.microsoft.com\/windows\/msix\/desktop\/desktop-to-uwp-packaging-dot-net\">Windows\nApplication Packaging project<\/a>.<\/li>\n<\/ul>\n<p>Let\u2019s click on \u201cBlank UWP App (Preview for .NET 9)\u201d to try it out\n(make sure to select Windows 11 22H2, build 26100, as the target\nframework, in the new project wizard), and let\u2019s inspect the resulting\nproject. You will notice that it combines all the familiar aspects of\nUWP XAML apps (the app manifest file, <code>App.xaml<\/code> with shared\nresources and basic initialization of the root <code>Frame<\/code> and\nnavigation to a page, and <code>MainPage<\/code>, the default XAML page\nthat is displayed when the application is launched), with things that\nshould be familiar to you if you\u2019ve worked with modern .NET before. In\nparticular, we now (finally! \ud83c\udf8a) have an SDK-style .csproj file (no more\nsuper verbose legacy-style .csproj with all individual XAML and C# files\nlisted!), and a <code>Properties<\/code> folder with some launch and\npublish settings.<\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Tip<\/strong><\/p>When creating a new\nproject with one of the preview templates, you might get an error dialog\nsaying \u201cOperation is not valid due to the current state of the object.\u201d.\nThis is due to the UWP Project Wizard in Visual Studio not supporting\n.NET 9 projects yet. This issue will be fixed in the next release of\nVisual Studio. As a temporary workaround, you can close Visual Studio,\nopen it again, manually open the .sln file that was created, and then\nright click &gt; Add &gt; Existing Project, and browse the new .csproj\nfile that was created. That error dialog does not prevent the actual\nproject from being created and saved on disk. If you\u2019re instead using\none of the new templates to create a project in an existing solution,\nthe new project should just show up correctly after dismissing the error\ndialog.<\/div><\/p>\n<p>For this initial preview (using Visual Studio 17.12 Preview 2),\nyou\u2019ll need to make a slight temporary modification to the .csproj in\norder for things to work. The UWP support for .NET 9 is currently\nrelying on the single-project MSIX tooling in Windows App SDK, which is\ncausing the WebView2 NuGet package to also be referenced by default. We\nhave made changes for it to support UWP .NET 9 apps as well, but those\nare not released publicly just yet. So for now, you need to manually\nexclude all assets from that NuGet package to avoid it causing build\nerrors. Without those, you\u2019ll probably see something like this in the\nerrors window when trying to build your project:<\/p>\n<div id=\"cb2\" class=\"sourceCode\">\n<pre class=\"sourceCode ps\"><code class=\"sourceCode postscript\"><span id=\"cb2-1\">Error WMC1006: \"Cannot resolve Assembly <span class=\"kw\">or<\/span> Windows Metadata <span class=\"kw\">file<\/span> 'Type universe cannot resolve assembly: System.Windows.Forms, <span class=\"kw\">Version<\/span>=<span class=\"dv\">4<\/span>.<span class=\"dv\">0<\/span>.<span class=\"fl\">0.0<\/span>, Culture=neutral, PublicKeyToken=b77a5c561934e089.'\"<\/span><\/code><\/pre>\n<\/div>\n<p>To fix this, we can add the following to the .csproj file:<\/p>\n<div id=\"cb3\" class=\"sourceCode\">\n<pre class=\"sourceCode xml\"><code class=\"sourceCode xml\"><span id=\"cb3-1\">&lt;<span class=\"kw\">PackageReference<\/span><span class=\"ot\"> Include=<\/span><span class=\"st\">\"Microsoft.Web.WebView2\"<\/span><span class=\"ot\"> Version=<\/span><span class=\"st\">\"1.0.2783-prerelease\"<\/span><span class=\"ot\"> IncludeAssets=<\/span><span class=\"st\">\"none\"<\/span> \/&gt;<\/span><\/code><\/pre>\n<\/div>\n<p>This is only temporary, and it will no longer be needed once the new\nupdate for this package is released.<\/p>\n<p>With all of these changes, we should end up with the following:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj.png\"><img decoding=\"async\" class=\"alignnone wp-image-771 size-full\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj.png\" alt=\"The .csproj for a UWP app targeting .NET 9 and NativeAOT, using the new preview UWP support for .NET 9\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj.png 1920w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj-300x169.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj-1024x576.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj-768x432.png 768w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-csproj-1536x864.png 1536w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>So clean! We just need a total of 16 lines of code (ignoring the\ntemporary WebView2 workaround), and nothing else! Alright, now that our\nnew project is ready, it\u2019s time to run our very first UWP .NET 9 app! We\ncan just click the green \u201cStart Debugging\u201d button in Visual Studio as always:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-772\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug.png\" alt=\"A UWP .NET 9 app running with the debugger in Visual Studio\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug.png 1920w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug-300x169.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug-1024x576.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug-768x432.png 768w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-blank-app-debug-1536x864.png 1536w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>And there it is: UWP XAML running on .NET 9! \ud83d\ude80<\/p>\n<p>We made changes to several components in Visual Studio to ensure a\ngreat developer experience. You\u2019ll notice:<\/p>\n<ul>\n<li>XAML IntelliSense is supported, including code completion,\nsuggestions, etc.<\/li>\n<li>XAML Live Preview shows up by default as it does in classic UWP<\/li>\n<li>XAML Diagnostics works as expected, and you can see the toolbar and\nthe live visual tree on the left<\/li>\n<li>All .NET diagnostic tools will work as expected: this is the same\nlatest .NET you know and love!<\/li>\n<li>We also support XAML Hot Reload (as well as C# Hot Reload)!<\/li>\n<\/ul>\n<p>This first preview does not include the XAML designer, but keep\nreading for more info on this!<\/p>\n<h2 id=\"the-project-in-detail\">The project in detail<\/h2>\n<p>Now that we\u2019ve successfully run our first UWP .NET 9 app, we should\ntake a moment to look into some technical details to better understand\nhow UWP .NET 9 projects are structured. You might notice a few\nproperties that are set automatically in the .csproj file by the project\ntemplate. This is what they\u2019re doing:<\/p>\n<ul>\n<li><strong>UseUwp<\/strong>: this property is used by the .NET 9 SDK,\nand it makes it reference the new WinRT projections for\nWindows.UI.Xaml.* types in the Windows SDK package for .NET projects. By\ndefault, these projections are not referenced, as they are incompatible\nwith WinUI 3. We don\u2019t want WinUI 3 developers to see both\nWindows.UI.Xaml (UWP XAML) and Microsoft.UI.Xaml (WinUI 3) types, as\nthat would be fairly confusing. Instead, we added these projections into\na separate .dll in the same framework package that all .NET Windows apps\nuse, and made it opt-in, via by the \u201cUseUwp\u201d property. Additionally,\nwhen this property is set, the .NET SDK enables a special feature switch\nfor CsWinRT, which projects all built-in .NET types as compatible with\nUWP XAML types, as opposed to WinUI 3 types. For instance, the <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.componentmodel.inotifypropertychanged\"><code>INotifyPropertyChanged<\/code><\/a>\ninterface will be projected as <a href=\"https:\/\/learn.microsoft.com\/uwp\/api\/windows.ui.xaml.data.inotifypropertychanged\"><code>Windows.UI.Xaml.Data.INotifyPropertyChanged<\/code><\/a>,\nas opposed to <a href=\"https:\/\/learn.microsoft.com\/windows\/windows-app-sdk\/api\/winrt\/microsoft.ui.xaml.data.inotifypropertychanged\"><code>Microsoft.UI.Xaml.Data.INotifyPropertyChanged<\/code><\/a>.\nIf you\u2019re curious to check out these changes, see the .NET PR (<a href=\"https:\/\/github.com\/dotnet\/sdk\/pull\/41936\">dotnet\/sdk\/#41936<\/a>)\nand the CsWinRT PR (<a href=\"https:\/\/github.com\/microsoft\/CsWinRT\/pull\/1421\">microsoft\/CsWinRT\/#1421<\/a>)\non GitHub.<\/li>\n<li><strong>UseUwpTools<\/strong>: this property tells several MSBuild\ncomponents that we\u2019re building a UWP app with support for .NET 9, and\nthat all necessary tooling for it should be enabled. For instance, it\nmakes Visual Studio automatically import all XAML files in the project,\nimport the XAML compiler, declare some necessary project capabilities,\nand more. It also makes MSBuild enable the APPX tooling when a class\nlibrary is being built. This allows creating UWP .NET 9 class libraries\nthat also include XAML items, as well as .resw files (for localized\nresources).<\/li>\n<li><strong>EnableMsixTooling<\/strong>: this property enables the\nsingle-project MSIX support, meaning you can create a UWP applications\nfrom a single .csproj file, as you\u2019d expect. As we mentioned, in this\nfirst preview we\u2019re relying on Windows App SDK to provide this support,\nbut we\u2019ll update this in the future to switch to a standalone NuGet\npackage providing single-project MSIX support for both UWP .NET 9 apps,\nas well as for Windows App SDK apps. When we do that, the issue of the\nWebView2 NuGet package being automatically referenced will also be\nfixed.<\/li>\n<\/ul>\n<p>These three properties are making all the magic happen so that we can\nnow build UWP XAML apps on latest .NET! \u2728<\/p>\n<p>Notice we\u2019re also setting <code>PublishAot<\/code> (<a href=\"https:\/\/learn.microsoft.com\/dotnet\/core\/deploying\/native-aot\/\">see\ndocs<\/a>) and <code>DisableRuntimeMarshalling<\/code> (<a href=\"https:\/\/learn.microsoft.com\/dotnet\/standard\/native-interop\/disabled-marshalling\">see\ndocs<\/a>) in the .csproj (and in all UWP .NET 9 project templates). This\nis because <strong>Native AOT is the only supported way for publishing\nUWP apps targeting .NET 9 in the Microsoft Store<\/strong>. This is meant\nto be a direct upgrade path for all UWP apps using <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/the-net-native-tool-chain\/\">.NET\nNative<\/a> today, and it also ensures that the usual fast startup of UWP\napps will be preserved. Additionally, the Microsoft Store does\n<strong>not<\/strong> allow publishing UWP apps using managed code, so of\ncourse, Native AOT provides us with a modern solution for that native\ncode requirement.<\/p>\n<p>It is worth calling out when migrating from .NET Native to Native\nAOT, you should expect a fair amount of friction and complexity in\nmaking sure that all of your code (including all of your dependencies)\nwill work correctly with Native AOT. At first, depending on your app,\nyou might see things stop working as expected until updated for AOT.<\/p>\n<p>On the bright side, working to enable Native AOT in your app will\nmake it much more resilient, and additionally, this work can be 100%\nreused if you then decided to also move from UWP to Windows App SDK in\nthe future. As they both leverage .NET, they are identical to respect to\nthe constraints and code changes needed for Native AOT support!<\/p>\n<p>With traditional UWP apps using .NET Native, you could find\ndifferences in behavior between Debug and Release and encounter all\nsorts of runtime crashes that would be difficult to debug or prevent.\nEven with a .NET Native app that was working, it was impossible to know\nfor sure that there weren\u2019t some hidden bugs here and there due to\nincorrect trimming. .NET Native provided a double-edged sword, as it\nrelied on lots of heuristics to try to make all .NET code \u201cjust work\u201d,\nmeaning it included pretty extensive fallback logic to try to make even\nthe most aggressive reflection paths work, and it would try to\nautomatically root .NET code for trimming if it thought it could be\nreflected on (e.g.\u00a0it had special handling of well-known libraries such\nas <a href=\"https:\/\/www.newtonsoft.com\/json\">Newtonsoft.JSON<\/a>). But\nthere was no way to statically prove that that would be the case,\nleading to these types of crashes you may have encountered while\ndeveloping your own apps as well.<\/p>\n<p>Native AOT, on the other hand, takes a drastically different approach\nand relies on static validation through code annotations and a set of\nanalyzers. You can learn more about this in <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/creating-aot-compatible-libraries\/\">this\nblog post on AOT compatibility<\/a>. Practically speaking, this means\nthat Native AOT has \u201cmuch less tolerance\u201d than .NET Native and requires\nall code to be properly annotated for AOT support ahead of time, but in\nreturn for this work it provides a guarantee that if an app can be built\nand published with Native AOT <strong>without producing any trim\/AOT\nwarnings<\/strong>, then <strong>it will run exactly the same<\/strong> as\nin a normal Debug build. This also means that any problems will show up\nmuch earlier in the development phase, and you\u2019ll be able to easily\ndebug them during your normal dev inner loop, without needing a Release\nbuild to test.<\/p>\n<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Information<\/strong><\/p>NativeAOT also has\nslightly different performance and binary size characteristics compared\nto .NET Native. We expect performance for NativeAOT on .NET 9 to be\nroughly equivalent to .NET Native (our benchmarks showed startup\nperformance between ~5% when compared to .NET Native, whereas backend\ncode not relying on WinRT interop should actually be consistently\nfaster). As for binary size, you might notice a ~4MB regression,\nespecially with smaller apps. This is due to .NET Native using a\nframework package for its runtime and class libraries (meaning all that\ncode was installed as a separate component and shared with other UWP\napps using the same version of .NET Native). NativeAOT, on the other\nhand, compiles all code into its output executable. This results in an\nincrease in binary size (which should be amortized as the size of the\napplication grows, however), but in return it also gives NativeAOT\nbetter performance, as it allows the compiler to perform\ninter-procedural optimizations with code from the .NET BCL, such as eg.\ninlining and optimizing code from the core libraries depending on the\nspecific use in your application. Improving both performance and binary\nsize metrics for NativeAOT and CsWinRT (the component handling all WinRT\ninterop on modern .NET) is something that is under active development,\nso expect regular improvements in this area in future\nreleases!<\/div><\/p>\n<p>One more bit of information with respect to the Microsoft Store\ncertification, if you\u2019re interested in trying to publish an update (or a\nnew app!) using the UWP support for .NET 9: we recommend ignoring <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/debug-test-perf\/windows-app-certification-kit\">Windows\nApp Certification Kit failures<\/a> when running the tool locally,\nespecially regarding \u201cunsupported Win32 APIs\u201d. These checks are in place\nbecause UWP apps were historically subjected to a particularly strict\nvalidation of all imported Windows APIs, which would trigger automatic\nfailure during certification if unsuccessful. This is no longer the\ncase, and Partner Center doesn\u2019t execute this Win32 API set validation\non UWP apps anymore, relying instead on the security model provided by\nAppContainer itself. That is, rather than trying to detect all \u201cunsafe\u201d\nWin32 APIs and fail certification, all APIs are allowed, and\nAppContainer will simply make them fail at runtime if they tried to\nperform any operation that wasn\u2019t allowed. This is especially relevant\nfor Native AOT, as it includes several Win32 imports for APIs that are\nnot in the allowlist for UWP apps, but that are completely fine to use\nfrom UWP (and in fact, work just fine). Because of this, you can still\nrely on WACK to perform basic validation before uploading a package to\nthe Microsoft Store (it\u2019s especially useful to double check that no\nmandatory asset is missing from the manifest, for instance), but you\nshould not worry about false-positive errors it reports about disallowed\nWin32 APIs.<\/p>\n<h2 id=\"but-wait-theres-more\">But wait, there\u2019s more!<\/h2>\n<p>Enabling the latest .NET for UWP applications not only provides an\nupgrade path to existing UWP developers, but it also improves existing\nscenarios that were previously limited by the legacy .NET infrastructure\nand limitations that managed UWP apps have had from the start. Let\u2019s\ntake a quick look at some other benefits that the UWP support for .NET 9\nbrings to the table.<\/p>\n<p>For those of you working on complex apps combining multiple\nUI-frameworks, where some controls are leveraging <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/desktop\/modernize\/xaml-islands\/xaml-islands\">UWP\nXAML Islands<\/a> (i.e.\u00a0hosting UWP XAML controls inside a Win32 app),\nthe UWP support for .NET 9 brings improved support for this scenario,\nthanks to the switch to the latest .NET and Native AOT! It is now\npossible to have a single project, using .NET 9, representing a packaged\nfull trust (or <a href=\"https:\/\/learn.microsoft.com\/windows\/msix\/msix-container\">partial\ntrust<\/a>) Win32 app, as well as the hosted UWP component to be placed\nin the visual tree! You can even combine everything into a single,\nnative binary, without having to worry about the UWP components\nrequiring a separate build toolchain that\u2019s difficult to integrate with\nthe rest of your application.<\/p>\n<p>Here is an example showcasing how the native UWP <a href=\"https:\/\/learn.microsoft.com\/uwp\/api\/windows.ui.xaml.controls.maps.mapcontrol\"><code>MapControl<\/code><\/a>\ncan be hosted inside a full trust packaged Win32 app (e.g.\u00a0it could be a\nWindows Forms app, a WPF app, a WinUI 3 app, etc.), and used just like\nany other controls. You can do the same with any other UWP XAML controls\nas well!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands.png\"><img decoding=\"async\" class=\"alignnone wp-image-773 size-full\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands.png\" alt=\"A UWP XAML islands example with .NET 9 and MapControl, which is made possible via the new preview UWP support for .NET 9\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands.png 1920w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands-300x169.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands-1024x576.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands-768x432.png 768w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/uwp-xaml-islands-1536x864.png 1536w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>You can find a full sample using C++\/WinRT in the <a href=\"https:\/\/github.com\/microsoft\/WindowsAppSDK-Samples\/tree\/main\/Samples\/Islands\">WindowsAppSDK-Samples\nrepo<\/a>, which shows all the code that\u2019s needed in detail. A C#\nimplementation would be very close to this, with just minor differences\ndue to different ways of doing interop with native APIs between C++ and\nC#. We\u2019ll also soon be updating the samples to include a Windows App SDK\napp hosting XAML Islands via a UWP .NET 9 app too, so you can just use\nthat as a reference if you\u2019d like to experiment with this in your own\napp.<\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Tip<\/strong><\/p>As mentioned in the docs, the\nUWP <code>MapControl<\/code> relies on Bing Maps for Enterprise, which is\ndeprecated and will be retired. Thankfully though, the data sources for\nthe control are fully customizable. For this demo, we used the <a href=\"https:\/\/www.openstreetmap.org\/\">OpenStreetMap<\/a> data sources\ninstead, which you can also leverage if you plan on using this control.<\/div><\/p>\n<h3 id=\"theres-even-more\">There\u2019s even more!<\/h3>\n<p>Adding support for the latest version of .NET and switching from .NET\nNative to Native AOT also brings massive improvements to one particular\nscenario: using <a href=\"https:\/\/learn.microsoft.com\/dotnet\/fsharp\/\">F#<\/a> on UWP! While\nyou can\u2019t use F# for your app layer with XAML, just like WinUI 3, you\ncan now reference dependencies or other projects that are built with\nF#!<\/p>\n<p>.NET Native, to this day, has some hard blocks that detect F#\nassemblies and immediately fail compilation, and even trying to manually\npatch some Visual Studio files to bypass those blocks, a lot of\nscenarios would still simply fail to compile or work at all, because the\n.NET Native toolchain simply was never designed to handle many of the\ncommon patterns of F# code. There is a <a href=\"https:\/\/github.com\/dotnet\/fsharp\/issues\/1096\">long standing and\nvery popular issue<\/a> in the F# repo asking for F# support for .NET\nNative, which has since been closed without being completed. With the\nUWP support for .NET 9, all of this no longer applies, as you\u2019ll be\nusing the same Native AOT runtime that already fully supports using F#\nwith any other project type as well!<\/p>\n<p>If you are a F# enthusiast and would like to try this out, don\u2019t\nforget to share your findings and tell us about your experience! \ud83e\uddea<\/p>\n<h3 id=\"theres-even-more-1\">There\u2019s <em>even<\/em> more!<\/h3>\n<p>The UWP support for .NET 9 also enables one more thing that might be\nuseful for library authors in some advanced scenarios. Like we\nmentioned, the new \u201cUseUwp\u201d property tells the .NET SDK to add a\nreference to the Windows.UI.Xaml.* projections for .NET, which is\nnecessary for UWP XAML apps. However, while <em>using<\/em> these types\nis only allowed in UWP XAML apps, <em>referencing<\/em> these projections\nis something that any .NET project can do. What this means is that it is\nnow possible to have a single .NET library (or WinRT projection\nassembly) including some UWP XAML types in the public API surface, and\nconsume it from both UWP apps (or libraries) and Win32 ones.<\/p>\n<p>Imagine you have a WinRT component that is consumed from multiple\nplaces, some of which might be UWP, some Win32. Let\u2019s say you decide to\nadd one specific API that takes or returns a UWP XAML type as well, to\nsupport a specific scenario. Previously, that would\u2019ve been impossible:\nUWP XAML types simply did not exist on latest .NET, so there was no way\nto reference them at all. However, it is now instead possible to add a\nreference to them (by setting the \u201cUseUwp\u201d property), and still be\nconsumed by both UWP and Win32 (which of course will not be able to\nactually use those specific APIs with UWP XAML types), without the need\nto either ship two different assemblies that only differ by a handful of\nAPIs, or resort to other workarounds to \u201chide\u201d the types from the API\nsurface of the library (e.g.\u00a0such as only taking an <code>object<\/code>\nor <code>IInspectable*<\/code> parameter instead of the actual type).<\/p>\n<p>This is only meant for very advanced scenarios (and comes with some\nadditional caveats, especially in case the library also references or is\nconsumed by Windows App SDK, since CsWinRT can only project either UWP\nXAML or WinUI 3 types in a given process), but it is yet another benefit\nthat comes as a side bonus from this preview support. For instance, we\ncan take advantage of this feature in some internal libraries used by\nseveral inbox apps and Windows modules, that ship as WinRT components\n(meaning they could leverage this for their .NET projections), because\nsome APIs reference UWP XAML types that could not previously be\nprojected correctly when the latest .NET version was being used.<\/p>\n<h2 id=\"whats-next\">What\u2019s next?<\/h2>\n<p>As we mentioned before, this first preview does not include a XAML\ndesigner in Visual Studio. However, we are already working on this, and\nthanks to <a href=\"https:\/\/github.com\/ahmed605\">Ahmed Walid<\/a>, a\nMicrosoft MVP and Windows developer, who has been helping us put\ntogether this first preview (a huge shout-out to him, thank you!), we\nalready have a working prototype complete with the \u201cProperties\u201d windows\nas well! You can see it in action here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1.png\"><img decoding=\"async\" class=\"alignnone wp-image-791 size-full\" src=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1.png\" alt=\"The XAML designer for UWP apps targeting .NET 9\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1.png 1920w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1-300x169.png 300w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1-1024x576.png 1024w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1-768x432.png 768w, https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-content\/uploads\/sites\/61\/2024\/09\/xaml-designer-1-1536x864.png 1536w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>We\u2019ll be working on integrating this prototype into an upcoming\nrelease of Visual Studio, so stay tuned! Here\u2019s also some of the other\nthings we\u2019re looking into right now, and that you can expect to see\navailable in the near future:<\/p>\n<ul>\n<li>We are working with the <a href=\"https:\/\/github.com\/microsoft\/testfx\">MSTest<\/a> team to add UWP\nsupport for .NET 9. We plan on reusing most of the new infrastructure\nthat packaged WinUI 3 apps also use, meaning UWP .NET 9 apps will\nbenefit from all the latest MSTest tooling as well, and the migration\nfrom UWP targeting .NET 9 to WinUI 3 should be especially smooth, for\ndevelopers that want to fully transition to Windows App SDK.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/microsoft-ui-xaml\">WinUI 2<\/a>\nsupport is coming soon! We already have internal builds that we are\ntesting, and we will publish a public preview of them in the near\nfuture. Of course, these will include AOT-compatible WinRT projections\nfor .NET, just like <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/windows-app-sdk\/preview-channel#version-16-preview-1-160-preview1\">Windows\nApp SDK 1.6<\/a>!<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/Win2D\">Win2D<\/a> already\nsupports UWP with .NET 9, and you can try it out today by using the\nlatest preview version of its UWP package (<a href=\"https:\/\/www.nuget.org\/packages\/Win2D.uwp\/1.28.0-preview1\">1.28.0-preview1<\/a>).\nWe will be releasing a stable version with UWP support for .NET 9\nshortly.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/XamlBehaviors\">XamlBehaviors<\/a>\nsupport is in progress. In fact, you can also check out <a href=\"https:\/\/github.com\/microsoft\/XamlBehaviors\/pull\/256\">the PR on\nGitHub<\/a>!<\/li>\n<li><a href=\"https:\/\/github.com\/CommunityToolkit\/Windows\">Windows\nCommunity Toolkit<\/a> support is also coming soon!<\/li>\n<\/ul>\n<h2 id=\"summary\">Summary<\/h2>\n<p>We\u2019re so excited to help UWP developers modernize their apps and\nleverage the latest .NET and C# advancements, as they move toward WinUI\n3 and Native AOT.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>Like we mentioned in the\nintroduction, the UWP support for .NET 9 is available in preview, so\nexpect some rough edges as we work on improving the developer\nexperience! We hope that in the long run, this will become the preferred\nway for UWP apps to use .NET and C#, and that as many developers as\npossible will be able to upgrade their existing UWP apps from .NET\nNative to the latest .NET and Native AOT.<\/div><\/p>\n<p>If you hit any issues, there\u2019s multiple channels you can use to\nreport them:<\/p>\n<ul>\n<li>For CsWinRT specific issues (e.g.\u00a0WinRT interop failing), use <a href=\"https:\/\/github.com\/microsoft\/CsWinRT\">the CsWinRT repo<\/a>.<\/li>\n<li>For Microsoft Store or Partner Center related issues\n(e.g.\u00a0certification failures), use <a href=\"https:\/\/aka.ms\/microsoftstorediscord\">our Discord\nchannel<\/a>.<\/li>\n<li>For general questions, you can also find us in the <a href=\"https:\/\/discord.gg\/XrFZD7H\">UWP Community Discord server<\/a> (soon\nto be Windows App Community). Feel free to ask for help and guidance in\nthe appropriate channel (e.g.\u00a0<code>#dev-csharp<\/code>). There\u2019s lots of\nother developers from the community that can help, and plenty of\nMicrosoft folks also hang out in the server!<\/li>\n<li>For other general issues not related to the UWP support for .NET 9\nitself, use the existing support channels. For instance, use Feedback\nHub to report issues with existing UWP APIs, or <a href=\"https:\/\/github.com\/microsoft\/microsoft-ui-xaml\">the WinUI 2\nrepo<\/a> for WinUI 2 issues, etc.<\/li>\n<\/ul>\n<p>Lastly, we want to thank everyone who contributed to this preview and\nhelped make this project happen. This was a collaborative effort between\nseveral teams across all of Microsoft, including the .NET and .NET SDK\nteams, the MSBuild team, the .NET Native and .NET diagnostics team, the\nVisual Studio team (including the owners of project templates, XAML\ndiagnostics, and the UWP workload), the Windows App SDK and WinUI team,\nthe Win2D team, the Windows Community Toolkit team, the XamlBehaviors\nteam, the Edge team, and the Store team. We also want to thank two\nMicrosoft MVPs for their contributions: <a href=\"https:\/\/github.com\/ahmed605\">Ahmed Walid<\/a>, for his help\nprototyping a big part of the changes necessary across Visual Studio and\nthe XAML compiler, as well as testing out early preview bits and\nproviding extremely useful feedback for us, and <a href=\"https:\/\/github.com\/dongle-the-gadget\">Dongle<\/a>, for prototyping\na <a href=\"https:\/\/github.com\/dongle-the-gadget\/CsWinRT\">fork of\nCsWinRT<\/a> with Windows.UI.Xaml support, and associated <a href=\"https:\/\/github.com\/dongle-the-gadget\/CsWinRTProjectionForWindows\">WinRT\nprojections<\/a>, which we used as reference for implementing the final\nchanges we shipped as part of CsWinRT and the official Windows SDK\nprojections. Thank you! \ud83c\udfc6<\/p>\n<p><strong>Happy coding!<\/strong> \ud83d\udda5\ufe0f<\/p>\n<h2 id=\"glossary\">Glossary<\/h2>\n<p>There is very often confusion around all the various Windows\ntechnologies around UWP, in part because there are so many relevant\nconcepts that are tightly interconnected, and the lines are often blurry\nbetween then. Let\u2019s take this opportunity to try to provide some\nclarity. Here is a small summary of the main components that UWP and\nWindows App SDK apps interact with. Some of these components are\northogonal to each other, but still closely related:<\/p>\n<ul>\n<li><strong>MSIX<\/strong>: this is a <a href=\"https:\/\/learn.microsoft.com\/windows\/msix\/overview\">packaging\nmodel<\/a> used by Windows apps. It can be used by lots of different app\ntypes, including UWP, Win32, PWAs, etc., and it is usually adopted by\napps published in the Microsoft Store (however, the Microsoft Store <a href=\"https:\/\/developer.microsoft.com\/microsoft-store\/desktop-apps\">also\nsupports unpackaged Win32 apps<\/a>, and MSIX apps do not require being\nnecessarily distributed through the Microsoft Store). The main benefits\nof MSIX packaging are install reliability, easy updates, clean\nuninstall, and more. Unlike with Win32 apps, using MSIX is a requirement\nfor UWP apps.<\/li>\n<li><strong>Windows Packaging Project<\/strong>: this is an MSBuild\nproject type for <a href=\"https:\/\/learn.microsoft.com\/windows\/msix\/desktop\/desktop-to-uwp-packaging-dot-net\">packaged\nWindows applications<\/a> that was introduced years ago as part of <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/modern-work-app-consult-blog\/desktop-bridge-8211-the-bridge-between-desktop-apps-and-the\/ba-p\/316488\">Desktop\nBridge<\/a>. It can be used in advanced scenarios where the\nsingle-project MSIX architecture (i.e.\u00a0tooling that can generate an MSIX\npackage from a single project, e.g.\u00a0a .csproj project) isn\u2019t sufficient.\nFor instance, that is the case for UWP applications that also bundle\nseparate Win32 processes they rely on to execute some functionality. A\nsmall bit of trivia: the Microsoft Store uses this project type, as we\nbundle a small Win32 process we use to perform some actions outside of\nthe UWP sandbox, you can read more about this <a href=\"https:\/\/devblogs.microsoft.com\/ifdef-windows\/microsoft-store-open-source-series-appservices-library\/\">in\nour blog post on the AppServices library<\/a>.<\/li>\n<li><strong>AppContainer<\/strong>: this is a restrictive,\ncapability-based process environment. It is a lightweight container that\nWindows can use to run apps to further control their behavior and\nimprove security. Applications running inside an AppContainer must\ndeclare what resources they want to access (e.g.\u00a0using the camera, or\naccessing files on disk, or using the network, etc.), and users can\ngrant these permissions and also revoke them. Running inside\nAppContainer is possible for both UWP and Win32 apps. Almost all UWP\napps will run in AppContainer, as that is the default configuration for\nthem (and running a UWP app in full trust and outside AppContainer\nrequires a <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/packaging\/app-capability-declarations#custom-capabilities\">custom\ncapability<\/a> that has to be explicitly granted by Microsoft to each\napp that wants to use it, so this is happens rarely). When you see\npeople referring to the \u201cUWP sandbox\u201d, they\u2019re most definitely referring\nto AppContainer, which as we said is not exclusive to UWP, and in fact\nis recommended for Win32 apps too, if possible. You would get the same\nrestrictions for any Win32 app running in AppContainer as well, with\nminor differences.<\/li>\n<li><strong>UWP<\/strong>: this is an application model. UWP applications\nare tied to a <a href=\"https:\/\/learn.microsoft.com\/uwp\/api\/windows.applicationmodel.core.coreapplication\"><code>CoreApplication<\/code><\/a>\ninstance, and may or may not use XAML for their UI. UWP is considered a\nlegacy application model for modern Windows apps, and developers are\nencouraged to migrate to WinUI 3 for long-term support. UWP applications\ncan run on <a href=\"https:\/\/learn.microsoft.com\/shows\/one-dev-minute\/introduction-to-uwp-device-families\">any\nWindows device family<\/a> that supports the UWP contract. Nowadays, this\nmeans that UWP apps will be able to run on Windows Desktop, Xbox, IoT,\nand HoloLens. UWP applications have access to some exclusive APIs, such\nas <a href=\"https:\/\/learn.microsoft.com\/uwp\/api\/windows.ui.core.corewindow\"><code>CoreWindow<\/code><\/a>,\nand support features such as <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/launch-resume\/handle-app-prelaunch\">prelaunch<\/a>,\n<a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/launch-resume\/suspend-an-app\">suspension<\/a>,\nrunning under <a href=\"https:\/\/learn.microsoft.com\/windows-hardware\/design\/device-experiences\/modern-standby\">modern\nstandby<\/a> (for <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/launch-resume\/support-your-app-with-background-tasks#in-process-and-out-of-process-background-tasks\">out-of-process\nbackground tasks<\/a>), and more.<\/li>\n<li><strong>UWP XAML<\/strong>: this is a UI framework, managed by the <a href=\"https:\/\/learn.microsoft.com\/windows\/win32\/dwm\/dwm-overview\">Desktop\nWindow Manager<\/a>. It can only be used directly by UWP apps, or by\nWin32 apps via <a href=\"https:\/\/blogs.windows.com\/windowsdeveloper\/2018\/11\/02\/xaml-islands-a-deep-dive-part-1\/\">XAML\nIslands<\/a>. One of the main differences between UWP XAML and other UI\nframeworks is that UWP XAML is composited and rendered by the same\nWindows component that also composites and renders the rest of Windows.\nThis comes with both advantages and disadvantages. The main drawback of\nthis approach is that because the whole framework is part of Windows,\nservicing has to be tied to new Windows versions, and it\u2019s not possible\nto make new APIs (or, new controls, new styles, etc.) available on older\nversions of Windows (though see WinUI 2 below). Similarly, servicing bug\nfixes downlevel is also more complicated, as a Windows update is needed.\nThe advantages are that because the Windows compositor has access to the\nentire visual tree of the application, it can leverage this to make some\nexclusive things possible, such as global composition. This makes it\npossible to create more complex visual effects in some scenarios, such\nas having a XAML element with an <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/design\/style\/acrylic\">in-app\nacrylic brush<\/a> that\u2019s applied over a <a href=\"https:\/\/learn.microsoft.com\/windows\/win32\/direct3d12\/swap-chains\">swapchain<\/a>\nin the background. This type of advanced layering only works on UWP\nXAML.<\/li>\n<li><strong>WinUI 2<\/strong>: this is a <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/winui\/winui2\/\">UI library\nfor UWP XAML apps<\/a>, which includes several XAML controls, styles, and\nsome new APIs. Because it\u2019s built on top of UWP XAML, it can only be\nused by UWP XAML apps. Just like with WinUI 3 (see below), one of the\nmain benefits of WinUI 2 is that it allows making new controls\navailable, as well as providing new styles and bug fixes, to downlevel\nversions of Windows as well. It also allows developers to rely on a\nconsistent visual style for their controls regardless of what version of\nWindows their app is running on.<\/li>\n<li><strong>WinUI 3<\/strong>: this is a <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/winui\/winui3\/\">complete\nXAML-based UI framework<\/a>, that is included in Windows App SDK (see\nbelow). Unlike UWP XAML, this framework is self-contained and manages\nits own rendering and compositing, meaning all of it can be updated\nseparately from Windows. It is supported for Win32 apps only. Note that\nas we mentioned, while Windows App SDK includes WinUI 3, using this UI\nframework is not mandatory when referencing Windows App SDK, and it is\ncompletely valid to use Windows App SDK from any application type that\ncan reference it, just for the other functionality it provides.<\/li>\n<li><strong>Windows App SDK<\/strong>: this is <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/windows-app-sdk\/\">an SDK\nfor building Windows apps<\/a>. It is made up of several components,\nwhich include lots of general purpose APIs to provide functionality to\nexisting apps, as well as WinUI 3. Contrary to components in UWP and UWP\nXAML, Windows App SDK ships as a NuGet package and can be consumed like\nany other library, meaning that it can be versioned and updated\nindependently of Windows. This also makes it very easy to backport new\nfeatures and bug fixes to downlevel versions of Windows, as almost all\nfunctionality is just in the Windows App SDK runtime library, which can\nbe referenced either as a <a href=\"https:\/\/learn.microsoft.com\/windows\/apps\/desktop\/modernize\/framework-packages\/framework-packages-overview\">framework\npackage<\/a>, or bundled in the application package (in self-contained\nmode).<\/li>\n<li><strong>Win32<\/strong>: this is <a href=\"https:\/\/learn.microsoft.com\/windows\/win32\/desktop-programming\">a\nset of APIs for Windows applications<\/a>, originally for C\/C++ programs.\nInformally, the name \u201cWin32\u201d is also used to refer to \u201cnon UWP\u201d\napplications, i.e.\u00a0non-<code>CoreApplication<\/code> apps. For instance,\nWindows Forms, WPF, and WinUI 3 apps would be examples of \u201cWin32 apps\u201d,\nand this is what people often refer to when they use \u201cWin32\u201d as a term\nopposite to \u201cUWP\u201d. However, note that <a href=\"https:\/\/learn.microsoft.com\/uwp\/win32-and-com\/win32-and-com-for-uwp-apps\">Win32\nAPIs can also be used by UWP apps<\/a>, and the two are not mutually\nexclusive. Of course, there are some restrictions that apply when using\nWin32 apps from UWP. Some are due to different device families, e.g.\u00a0you\ncan\u2019t use APIs such as <a href=\"https:\/\/learn.microsoft.com\/windows\/win32\/learnwin32\/creating-a-window\"><code>CreateWindow<\/code><\/a>\nto create and show a window when running on Xbox (although it will work\nwhen running on Windows Desktop, even on UWP). Some are due to\nAppContainer, e.g.\u00a0by default you can\u2019t just use <a href=\"https:\/\/learn.microsoft.com\/windows\/win32\/fileio\/creating-and-opening-files\"><code>CreateFile<\/code><\/a>\nto open a file from an arbitrary location on the system you don\u2019t have\naccess to. However, note that this restriction is mostly due to\nAppContainer, not UWP itself, meaning a packaged partial trust Win32 app\n(e.g.\u00a0a WinUI 3 app running under AppContainer) would also have the same\nissue here.<\/li>\n<li><strong>WinRT<\/strong>: this is a set of modern, object-oriented\nAPIs for building Windows applications. They are designed to be\nlanguage-agnostic (e.g.\u00a0they can be consumed by any language that\nsupports WinRT projections, such as C++, C#, JavaScript, Rust), and\nprovide access to a wide range of functionalities and Windows\ncapabilities, including touch input, sensors, and interacting with the\nMicrosoft Store. The UWP platform is built on top of WinRT APIs (in\nfact, the name \u201cUWP API\u201d is often used informally to mean \u201cWinRT API\u201d).\nNote that WinRT APIs are not exclusive to UWP apps, and generally they\ncan be used by any application type. All UWP types mentioned before,\nsuch as <code>CoreApplication<\/code>, as well as all UWP XAML types, are\nactually WinRT APIs. Windows App SDK itself is also a WinRT component,\nand almost all APIs it exposes are using the WinRT contract.<\/li>\n<\/ul>\n<p><strong>TLDR:<\/strong> in general, a \u201cUWP app\u201d is a\n<code>CoreApplication<\/code> app, packaged with MSIX, running under\nAppContainer, using a combination of WinRT and Win32 APIs. If it is a\nXAML app, it uses the UWP XAML UI framework, and it can optionally use\nthe WinUI 2 library as well.<\/p>\n<p>We hope that this small summary will prove useful in making the\nrelationships between all of these components a bit easier to\nunderstand. With this, you can also now see where the UWP support for\n.NET 9 comes in: it targets UWP apps (possibly using UWP XAML and WinUI\n2 as well), and it allows you to simply swap the .NET runtime they use\nfrom <a href=\"https:\/\/learn.microsoft.com\/windows\/uwp\/dotnet-native\/\">.NET\nNative<\/a> to <a href=\"https:\/\/learn.microsoft.com\/dotnet\/core\/deploying\/native-aot\/\">Native\nAOT<\/a>, which also includes upgrading to the latest version of .NET and\nC#.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>We\u2019re working on improving the\nofficial documentation to also provide a single place to easily access\nall the information from this glossary, and more. We will update this\nsection with a link to that new documentation when it becomes available\non Microsoft Learn.<\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re introducing the initial preview UWP (Universal Windows Platform) support for .NET 9, providing a path for existing UWP developers to modernize their apps with the latest .NET and Native AOT. Are you a UWP app developer considering migrating to Windows App SDK and WinUI 3? Or wanting to leverage the latest releases of .NET [&hellip;]<\/p>\n","protected":false},"author":81469,"featured_media":770,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[4,51,10,61,49,59,5,37,8,54,6,7,15],"class_list":["post-769","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ifdef-windows","tag-net","tag-csharp","tag-desktop","tag-developer","tag-dotnet","tag-microsoft-store","tag-uwp","tag-win32","tag-windows","tag-windowsappsdk","tag-winui","tag-winui3","tag-xaml"],"acf":[],"blog_post_summary":"<p>We\u2019re introducing the initial preview UWP (Universal Windows Platform) support for .NET 9, providing a path for existing UWP developers to modernize their apps with the latest .NET and Native AOT. Are you a UWP app developer considering migrating to Windows App SDK and WinUI 3? Or wanting to leverage the latest releases of .NET [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/posts\/769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/users\/81469"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/comments?post=769"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/posts\/769\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/media\/770"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/media?parent=769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/categories?post=769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ifdef-windows\/wp-json\/wp\/v2\/tags?post=769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}