Juggern Ott
Juggern Ott

Reputation: 81

VS2019 + Xamarin.Forms = UWP/EXE dropped?

How do I get the UWP back into Xamarin.Forms Cross-Platform creation to have the templates ready to roll?

After picking through the release notes, playing with VS2019's UI and a few hours of web searching, I have only found others posting about the problem in the preview versions. Some say UWP is gone forever, some say it just isn't included by default (so Microsoft can brag about how the install went from 23GB to 8GB or something like that) - but no help on HOW TO re-enable it, or add it to the project creation wizard (apart from adding a blank UWP project sans all code that is in the iOS/Android projects).

<Project Sdk="Microsoft.NET.Sdk">
// the code is not the problem here,
// getting TO the code is the problem
</Project>

EXPECTED: In VS2017, Xamarin.Forms Cross-Platform supplied iOS + Android + UWP templates by default.

ACTUAL: Visual Studio 2019 seems to have removed the UWP template from Xamarin.Forms Cross-Platform project creation.

Upvotes: 2

Views: 3416

Answers (3)

Juggern Ott
Juggern Ott

Reputation: 81

EDIT (7/17/2021): i have started a new xamarin forms solution and it seems all 3 platforms are available again in VS2019 on all prebuilt templates (blank, master-detail, tabbed layout).

thank you, everyone, for your input. great information! it helped me steel myself to face the fact: UWP is gone (for now) from Xamarin.Forms new project scaffolding.

but, the (simplest) solution to the question asked that i have found is: open VS2017. create new Xamarin.Forms cross-platform project. once it is open, save-all. then close VS2017 and open in VS2019 if so desired.

Upvotes: 0

magicandre1981
magicandre1981

Reputation: 28776

With the Update 16.0.1, Microsoft restored the UWP creation on new Xamarin.Forms applications

enter image description here

except when you try to use Shell, which is not available for UWP:

enter image description here

Issues fixed in Visual Studio 2019 version 16.0.1

Add option for Windows (UWP) platform when creating new Xamarin.Forms project from 'Mobile App (Xamarin.Forms)' project template.

Upvotes: 0

Gerald Versluis
Gerald Versluis

Reputation: 34013

Update 9 apr.: a new version of 2019 was released which reinstates the UWP templates again

It is correct that the UWP template is removed from VS2019, I don't know the reason behind it, but we'll have to deal with it. There is however a page that runs you through the process step by step. It has been there for a while for the projects that were created in Visual Studio for Mac, which don't include the UWP template as well. The full description can be found here: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/windows/installation/ taken from this page:

First, right-click on the solution and select Add > New Project... and add a Blank App (Universal Windows) project:

Select Blank App template

Then, select the minimum and targeted UWP versions.

Right-click on the UWP project and select Manage NuGet Packages... and add the Xamarin.Forms package. Ensure the other projects in the solution are also updated to the same version of the Xamarin.Forms package.

Also, make sure the new UWP project will be built in the Build > Configuration Manager window (this probably won't have happened by default). Tick the Build and Deploy boxes for the Universal project:

Build configuration

Right-click on the UWP project and select Add > Reference and create a reference to the Xamarin.Forms application project (.NET Standard or Shared Project).

In the UWP project, edit App.xaml.cs to include the Init method call inside the OnLaunched method around line 52:

// under this line
rootFrame.NavigationFailed += OnNavigationFailed;
// add this line
Xamarin.Forms.Forms.Init (e); // requires the `e` parameter

In the UWP project, edit MainPage.xaml by removing the Grid contained within the Page element. Then in MainPage.xaml, add a new xmlns entry for Xamarin.Forms.Platform.UWP, like this: xmlns:forms="using:Xamarin.Forms.Platform.UWP".

In MainPage.xaml, change the root <Page element to <forms:WindowsPage, like this:

<forms:WindowsPage
...
   xmlns:forms="using:Xamarin.Forms.Platform.UWP"
...
</forms:WindowsPage>

In the UWP project, edit MainPage.xaml.cs to remove the: Page inheritance specifier for the class name (since it will now inherit from WindowsPage due to the change made in the previous step)

public sealed partial class MainPage // REMOVE ": Page"

In MainPage.xaml.cs, add the LoadApplication call in the MainPage constructor to start the Xamarin.Forms app:

// below this existing line
this.InitializeComponent();
// add this line
LoadApplication(new YOUR_NAMESPACE.App());

Add any local resources (eg. image files) from the existing platform projects that are required.

And now it should work as before. I know, it's a hassle to go through it for something that just worked before. Sorry about that, but this should get you there as well.

Upvotes: 4

Related Questions