.NET Standard Comes To The Xamarin.Forms Project Templates

Introduction

.NET Standard is a formal particular of the .NET APIs that enable you to share much more code over the stages you target. Xamarin designers can utilize .NET Standard libraries for sharing business logic, and .NET Standard support came to Xamarin.Forms as of late, enabling you to effectively share both your business and UI rationale over numerous stages. You've been asking us when you can File - > New - > Mobile App with Xamarin.Forms and .NET Standard, and we're eager to share this is currently accessible in the Visual Studio 2017 version 15.5 Preview 3.

In this blog entry, you'll figure out how to utilize new project templates in Visual Studio 2017 that empower you to use .NET Standard as a code sharing strategy while making new Xamarin.Forms applications. We'll additionally investigate a portion of alternate changes that arrived in our Xamarin.Forms formats in Visual Studio 2017 adaptation 15.5, for example, relocation to PackageReference and checkboxes for choosing which stages to target.
 
File -> New Project

You can get started with a new Xamarin.Forms app by going to File -> New -> Visual C# -> Cross-Platform -> Cross-Platform App. This template allows you to select what kind of starter project you’d like, what platforms you plan on targeting, and your code sharing strategy.

.NET

.NET Standard

.NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET runtimes (such as .NET Framework, Mono, and .NET Core). In real terms, you can think of this as a simplified, yet expanded, Portable Class Library. Any code added to a .NET Standard library can be used on any runtime that supports the .NET Standard Platform. In addition, we get expanded access to APIs within the .NET base class libraries (.NET Standard 2.0 adds over 20,000 new APIs!), support more platforms, and we don’t ever have to deal with the madness that is PCL profiles.

To use the .NET Standard code sharing strategy with Xamarin.Forms, select the .NET Standard radio button. Portable Class Library is no longer available as an option from File -> New, but existing class library projects will continue to build and work!

PackageReference

.NET developers know the pain that is packages.config. This file is meant to be a canonical list of all NuGet packages referenced by an app, but quickly turns into an unmanageable mess. The problem with packages.config is that it’s not just a list of all the packages explicitly added, but also the packages my packages reference.

PackageReference is a new way to manage your NuGets directly in the .csproj file, rather than a separate file. One of my favorite things about PackageReference is that all packages listed are transitively restored, meaning that you only need to define the top-level NuGets that your app consumes; no more dealing with the 100s of packages that your packages reference.

To manage packages, you can use the NuGet Package Manager or directly edit your .csproj to add something like this:

  1. <ItemGroup>  
  2.    <PackageReference Include="Xamarin.Forms" Version="2.4.0.282" />  
  3. </ItemGroup>   

All templates in our cross-platform app wizard now use PackageReference by default.

Pick Your Platform

Mobile developers often begin a project with certain platforms in mind. We wanted our File -> New Project to reflect that experience, so we added checkboxes to allow you to select which platforms you care about when creating mobile apps.

Wrapping Up

This blog post talked about how you can File -> New -> Mobile App with Xamarin.Forms and .NET Standard. We also covered some key improvements to our cross-platform templating wizard, including migration to PackageReference and target platform checkboxes for selecting which platforms you care about.

You can get these changes today by downloading Visual Studio 2017 version 15.5, currently in preview. With Visual Studio 2017, it’s now easier and safer for you to try new Xamarin previews. Visual Studio 2017 Preview installs side-by-side with Visual Studio 2017, and is sandboxed to prevent anything in your preview environment from affecting your stable environment, so be sure to give our new templates a try today! These templates are Visual Studio-only for the moment, but will be making their way to Visual Studio for Mac sometime soon. 

Ebook Download
View all
Learn
View all