Volume 33 Number 1
[Universal Windows Platform]
What’s New for .NET UWP Development?
By Daniel Jacobson | January 2018
Back in October 2015, one of us had the pleasure to author an article about .NET Universal Windows Platform (UWP) development (msdn.com/magazine/mt590967). A lot has changed with .NET UWP development since then, and we wanted to address those changes with a new article that helps get developers up to speed.
Since October 2015, Microsoft has published a new release of Visual Studio 2017, several new SDKs (including the most recent Windows 10 Fall Creators Update SDK), the Windows Application Packaging Project, .NET Standard 2.0 support, improvements to NuGet, the new Fluent design system, new community driven tools including Windows Template Studio, and more. Many of these changes and improvements to the UWP developer ecosystem are designed to make it easier to bring your existing .NET assets forward, optimize your application deployment strategy on Windows 10, and accelerate your UWP development to build great applications as quickly as possible.
The Windows 10 Fall Creators Update brings a host of improvements for UWP developers, with Visual Studio 2017 version 15.5 and later providing the best support for the Windows 10 Fall Creators Update SDK (10.0.16299.0). Some of the most important changes include new capabilities for enterprise applications, streamlined application deployment, and support for both .NET Standard 2.0 and the new Fluent Design System. Let’s explore these advancements.
New Capabilities in Windows for Enterprise Applications
Microsoft recognized the need to improve the Windows 10 Platform for enterprise developers building applications for Windows on desktop PCs and has made important strides in this area with the Windows 10 Fall Creators Update.
Best of Both UWP and Win32 Microsoft has improved the Windows 10 Platform with the Desktop Bridge (aka.ms/desktopbridge) to enhance its appeal to all .NET developers, whether their current focus is on the UWP, Windows Presentation Foundation (WPF), Windows Forms or Xamarin. With the new App Packaging project type in Visual Studio 2017 version 15.5, you can create Windows App Packages for your WPF or Windows Forms projects, just like you can for UWP projects.
Once your application is packaged, you get all the Windows 10 application deployment benefits, including the option to distribute via the Microsoft Store (for consumer apps), the Microsoft Store for Business and Education, or via any of your favorite app deployment options such as Intune. Packaged apps have access to both the full UWP API surface and the Win32 APIs on desktop, so you can modernize your WPF and Windows Forms applications gradually with UWP APIs and Windows 10 features. You can also include your Win32 components in your UWP apps so that they light up on the desktop with all Win32 capabilities.
Peace of Mind Users can install apps without regret and without concern that they contain malware. Installations don’t require admin privileges, and each application install is isolated from others, easing management. Uninstalls are guaranteed to be clean, with no rot in the Registry or file system or other unexpected side effects from installing software. This method of distribution is now also available for your WPF and Windows Forms applications using the Windows Application Packaging Project.
Enterprise-Ready Security Windows Hello enables biometric authentication for devices and compatible apps. The Windows 10 App Model protects your data and system health through UWP app containers, which put the user in control over what apps can and cannot do. In addition, apps must disclose their usage of resources, such as location or microphone, which the user or IT administrator controls via privacy settings.
Closing Gaps for Desktop Applications The recent Fall Creators Update release has helped close the API and feature gaps between UWP and Win32 desktop applications. Support for .NET Standard 2.0 has significantly increased the available API surface, while providing access to many important NuGet packages that previously could not be used in UWP projects. For example, enterprise developers finally get access to SqlClient APIs to talk directly to SQL Server databases from their UWP projects. Microsoft also continues to improve the UWP App Model for desktop and enterprise scenarios. Recent updates have enabled command-line activation, auto-startup and capabilities for running with full-trust or with unrestricted execution lifetime (extendedBackgroundTaskTime and extendedExecutionUnconstrained).
Streamlined Application Deployment
Microsoft recognizes that many .NET developers are still building Windows Forms and WPF applications. In addition to making it as easy as possible to bring existing assets forward, the company aims to solve a problem that many developers face today: deployment. With Visual Studio 2017, it’s easier than ever to leverage the Desktop Bridge (aka.ms/desktopbridge) to package existing Win32 .NET applications.
You can certainly submit Win32 applications to the Microsoft Store with the Windows Application Packaging Project, but there are many other ways to distribute applications packaged as an .appx. These options support the deployment flexibility that many organizations require.
Beginning with the Windows 10 Fall Creators Update, you can host your own .appx installer on the Web to invoke the app installer automatically. It’s as simple as adding an activation scheme (ms-appinstaller:?source=) to the link to the .appx on the Web. For more information, check out the blog post on direct Web installs here: bit.ly/2mJfIUI. This approach makes it really easy to share applications within your organization, simply by posting a link to the .appx on a Web site, for example.
You can also create app installer manifests to support automatic package updates. One advantage that this app installer technology provides over a scheme like ClickOnce is that automatic updates happen behind the scenes--the application can update before the user of the application even launches it. To learn how to create your own custom .appinstaller files for automatic application updates in privately hosted deployment channels, check out the blog here: bit.ly/2z4Fx3A.
If you need more capable device management tools in your organization, you can leverage and distribute your applications with Microsoft Intune (bit.ly/2B7OnyR). The Windows Application Packaging Project is the fastest route to make your apps easily managed via Microsoft Intune.
Last but not least, you can distribute your applications via the Visual Studio App Center (bit.ly/2AKpsjJ). Visual Studio App Center allows for rapid deployment to your development teams or beta testers of your application. You can also easily enable analytics to determine who’s using your applications, and how they’re using them.
With the Windows Application Packaging Project and so many channels of distribution for .appx packages, it’s easy to package and distribute your application for any scenario in your organization.
Support for .NET Standard 2.0
The Windows 10 Fall Creators Update is the first release of Windows 10 to provide support for .NET Standard 2.0. If you’re unfamiliar with .NET Standard, you can get a lot of detail at aka.ms/dotnetstandard. Effectively, .NET Standard is a reference implementation of the base class library that any .NET platform can implement, be it .NET Framework, .NET Core or Xamarin. The goal of .NET Standard is to make it as easy as possible for .NET developers to share code across any .NET platform on which they choose to work.
While there are some similarities with the Portable Class Library (PCL) model, the biggest difference with .NET Standard is that you don’t have to choose which platforms you’re targeting. If the platform you target implements the base class library as defined by the standard, the shared code will work. A huge advantage of .NET Standard compared to PCLs is that when a new .NET Platform is introduced with .NET Standard support, you don’t need to modify your shared code libraries, because you won’t have to add any new platform target.
Early iterations of .NET Standard (versions 1.x) were a great start, but with the Windows 10 Fall Creators Update and .NET Standard 2.0, Microsoft has made it drastically easier to share code across .NET platforms. .NET Standard 2.0 has about 20,000 more APIs compared to any 1.x version. In addition, .NET Standard 2.0 is supported with the .NET Framework version 4.6.1, as well as UWP development for developers targeting the Windows 10 Fall Creators Update. We’ll explore the nitty gritty details regarding how all this works in the “.NET and UWP Development” section.
One other huge benefit of .NET Standard 2.0 is that it provides a path forward for many existing .NET applications (whether they’re WPF or Windows Forms). If your .NET apps target .NET Framework 4.6.1 or later, you can start porting your codebehind into .NET Standard 2.0 libraries. That same code can then be shared across any .NET Platform that implements .NET Standard 2.0. The .NET Standard Compatibility Matrix in Figure 1 shows how support plays out across versions.
Figure 1 .NET Standard Compatibility Matrix
This means you can start to port your code into reusable libraries, and when you’re ready, you can share the same code in UWP apps, Xamarin apps, .NET Core apps and more.
To assist you in determining if your code is API-compatible with .NET Standard 2.0, Microsoft created a portability analyzer that will produce a report showing which APIs are compatible with each .NET implementation (bit.ly/2zlgrBz). You can also check out a useful Channel9 video from .NET Conf 2017 that steps through the entire porting process, from a Windows Forms .NET application to a UWP application at bit.ly/2j9TB52.
Fluent Design System
With the evolution of computing devices and the emergence of mixed reality, it was essential that the Windows design system evolve, as well. To address this shift, Microsoft released the Fluent design system (fluent.microsoft.com). Built on top of five building block concepts—light, depth, motion, material and scale—this system is designed to support the next generation of UX across device types.
With the Windows 10 Fall Creators Update, you can already see Fluent artifacts making their way into Windows 10 and application development. A great way to see Fluent design in action is to take a look at the XAMLUIBasics sample in the UWP samples on GitHub (bit.ly/2mK4pvH).
Another sample (shown in Figure 2) that demonstrates Fluent design principles in a more enterprise-focused scenario can be found at aka.ms/eshopuwp/src. In this example, you can see the acrylic material that provides a composited layer in the navigation pane. You can also see light effects that serve to highlight the “Add new item” navigation button.
Figure 2 Fluent Design in Action
Improvements to Visual Studio 2017
There are many improvements in Visual Studio 2017 compared to Visual Studio 2015. Here, we’ll highlight some of the most important and impactful new capabilities of the IDE.
Let’s start with the latest tooling—Visual Studio 2017. One of the core priorities for Visual Studio 2017 was to make setup as fast and as easy as possible. As soon as you begin to install Visual Studio 2017, you’ll immediately recognize improvements over Visual Studio 2015.
Things get started with the Visual Studio Installer (see Figure 3), which allows you to manage all installations of Visual Studio 2017. It supports scenario-driven acquisition with the introduction of Workloads designed around what developers need to get their job done. Workloads make it so that you only install what you need, and not all the extra stuff that often made Visual Studio 2015 take so long to install. In addition, instances of Visual Studio 2017 can be installed side-by-side, so you can install preview versions (visualstudio.com/vs/preview) and retail versions (visualstudio.com) on the same machine. This lets you try out the latest and greatest features without impacting your production environment.
Figure 3 Visual Studio Installer
In addition, beginning with the Windows 10 Creators Update (10.0.15063.0), the SDK install can be set up side-by-side, as well. Now you can enroll in the Windows Insiders Program (insider.windows.com) and try out preview SDKs, again without breaking your production environment.
Improvements to the XAML Designer
Visual Studio 2017 version 15.4 introduced some drastic updates to the XAML Designer. These updates are centered on several design considerations, including:
- Significantly improved designer performance
- High-fidelity designer surface, focused especially on rendering artifacts introduced by the new Windows Fluent Design System
- Fewer designer exceptions to minimize distractions and maximize developer productivity in the design surface
- Improved designer UX without breaking or changing existing XAML development in Visual Studio and Blend
- Updated tools that help maximize the productivity of developers building Windows experiences.
These updates to the designer required a rethink of the designer’s underlying architecture. The impact on Windows developers in the short term is that Microsoft must rebuild much of the tooling with which developers have grown familiar. To manage this challenge, Microsoft has only released the updates to the XAML Designer to UWP developers targeting the Windows 10 Fall Creators Update (10.0.16299.0) or later. You can read about the updates in much greater detail at aka.ms/uwpsiblog.
Windows Application Packaging Project
To streamline application deployment with Windows 10, you can now create a new project type called the Windows Application Packaging Project. This project allows you to add references to Win32 applications (for example, Windows Forms and WPF) and package them using the .appx package format.
Taking advantage of this project is simple. Just add a new Windows Application Packaging Project to your solution and add a reference to your Win32 application using the Applications node, as shown in Figure 4.
Figure 4 WapProj Demo
To create packages, right-click on the Windows Application Packaging Project and select Store | Create App Packages. The output will be an .appx that you can deploy using any of the methods mentioned in the “Streamlined Application Deployment” section of this article.
Improvements to NuGet
With Visual Studio 2017, all .NET UWP apps take advantage of the NuGet package reference model for adding NuGet packages to projects (bit.ly/2AXDDlz). NuGet package references provide several benefits for both NuGet package authors and NuGet package consumers.
PackageReference has direct MSBuild integration, which enables new scenarios such as package management across multiple projects. Let’s consider an example. Say you work in an enterprise that has a core library shared across all (or many) projects that your enterprise produces. Traditionally, when an update to that library was made, every project that consumes that package would need to update the reference to take advantage of the latest version. With PackageReference, your enterprise can create a shared MSBuild target that gets imported into every project, and when an update to your core libraries are made, you can update the version in the custom MSBuild target. Every project that imports that MSBuild target will now reference the updated version of the library with no need to update every single project.
In addition, MSBuild integration enables conditional package references, which provides finer control over your project dependencies. Let’s consider the same example, but now producing both a Debug and Release version of the core library. The shared MSBuild target could specify conditional package dependencies to consume the Debug version of the library in Debug builds of the projects that consume the library. This way, you have the unoptimized version of the library to provide the best debugging experience. You can configure the conditional dependency to then switch to the Release version of the core library when building Release versions of the project.
Finally, for NuGet package authors, you can leverage platform multi-targeting in a single NuGet package. One great use case of platform multi-targeting is publishing a single NuGet package to support all .NET platforms. Let’s say you’ve previously built and managed a .NET Framework library on NuGet that you want to update to support .NET Standard 2.0. The latest version of your NuGet package can maintain both implementations so the latest version of the package is always applicable, regardless of the consuming project. For example, if you have a .NET Framework 4.5 implementation and a .NET Standard 2.0 implementation, any .NET application that’s targeting .NET Framework 4.5 or later or implements .NET Standard 2.0 will be able to consume the NuGet package. For UWP development, the specified platform is correlated to the TargetPlatformMinVersion of your project. If your TargetPlatformMinVersion is greater than or equal to the platform specified in the NuGet package, the NuGet package can be referenced in the project.
In Visual Studio 2015, the .NET Native compiler was shipped as part of Visual Studio. Even though the .NET Core implementation for UWP development was shipped as a set of NuGet packages, developers faced a slightly fragmented experience when it came to .NET Native. With Visual Studio 2017, all of .NET for UWP development ships as part of the .NET implementation for the UWP NuGet package, including .NET Native. This gives you the flexibility to move at your pace—by specifying the version of .NET that you need and that you know works for your application.
.NET Standard 2.0 and UWP Development
Previously mentioned in this article is that .NET Standard 2.0 is available in the Windows 10 Fall Creators update. To take advantage of the .NET Standard 2.0 implementation, you must set your TargetPlatformMinVersion of your UWP project to the Windows 10 Fall Creators Update or later, as shown in Figure 5. You must also reference the Microsoft.NETCore.UniversalWindowsPlatform NuGet package version 6.0 or later.
Figure 5 .NET Standard 2.0-Compatible UWP App
The Microsoft.NETCore.UniversalWindowsPlatform NuGet package takes advantage of platform multi-targeting support for UWP development so you can always update to the latest version of the package. If you are building an application that has a TargetPlatformMinVersion less than the Windows 10 Fall Creators Update, the NuGet restore process will bring in the .NET Standard 1.4 implementation of .NET Core for Windows 10. If you set the TargetPlatformMinVersion to the Windows 10 Fall Creators Update or later, NuGet will bring in the .NET Standard 2.0 implementation of .NET Core for Windows 10. Now, that was a lot of text—what it means for you is that you shouldn’t have to worry about which version of the NuGet package to reference. You can always reference the latest and it should always work, regardless of your Windows 10 target.
Useful Open Source Projects
Finally, we wanted to leave you with some helpful open source projects that you can use to accelerate UWP development. These include Windows Template Studio, the UWP Community Toolkit and the Telerik Controls for UWP Development.
Windows Template Studio Windows Template Studio (shown in Figure 6) is a dynamic template generator for UWP development. It’s the fastest way to get started building a production-ready UWP app. It leverages best practices for development, and lets you build many views, background tasks, and more in a simple wizard experience. Using Windows Template Studio for all new application development in an organization can help ensure consistent look and feel across apps and encourage best practices for application architectures. Built, maintained and updated by a passionate community of Windows developers, Windows Template Studio is a great way to get started building fully-fledged UWP apps (aka.ms/wts).
Figure 6 Windows Template Studio Project Generation
Telerik Controls for UWP Development Back in February 2017, Telerik announced that it was open sourcing the Telerik UI for UWP controls library. The license provides free use for anyone building UWP apps. Telerik has a history of building powerful, performant, enterprise-ready controls—and with UWP development they’re now free! Read more about the Telerik open source announcement on the company’s blog: bit.ly/2AZA0iI.
UWP Community Toolkit The UWP Community Toolkit (github.com/Microsoft/UWPCommunityToolkit) is another community-driven project that provides helpful tools for UWP development. The toolkit includes templated animations, controls, helper classes, services and more. Use the UWP Community Toolkit to accelerate your development.
It’s clear that a lot has changed for .NET and UWP developers, with so many new tools and updates to make building Windows applications as fast and easy as possible. With .NET Standard 2.0 and all the free resources available, it’s never been easier to build enterprise-ready applications with the Universal Windows Platform. For .NET developers, the Desktop Bridge platform and updated tooling combine to let you build powerful desktop applications that take advantage of the best of UWP and Win32, including WPF and Windows Forms. Microsoft is constantly improving its tools based on your feedback, so as you build your Windows applications, don’t hesitate to reach out by e-mail or Twitter.
Thanks to the following Microsoft technical experts for reviewing this article: Mike Harsh, Matthijs Hoekstra, Unni Ravindranathan and Ricardo (Rido) Minguez
Unni Ravindranathan is a program manager on the Visual Studio team focusing on building world-class tools for developers building Windows applications.
Mike Harsh is a group program manager on the Windows Developer Platform team.
Matthijs Hoekstra is a senior program manager on the Developer Platform team.