VS2019 + Xamarin.Forms = UWP/EXE掉线了吗? [英] VS2019 + Xamarin.Forms = UWP/EXE dropped?

查看:262
本文介绍了VS2019 + Xamarin.Forms = UWP/EXE掉线了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将UWP重新带回Xamarin.Forms跨平台创建中,以使模板准备就绪?

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

在仔细阅读发行说明,使用VS2019的UI和几个小时的网络搜索之后,我只发现其他人在预览版本中发布了有关该问题的信息.有人说UWP永远消失了,有人说默认情况下不包含UWP(因此Microsoft可以吹嘘安装的方式从23GB扩展到8GB或类似的东西)-但是在如何重新启用它方面没有任何帮助或添加它添加到项目创建向导中(除了添加一个空白的UWP项目之外,没有iOS/Android项目中的所有代码).

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>

预期: 在VS2017中,默认情况下,Xamarin.Forms跨平台提供了iOS + Android + UWP模板.

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

实际: Visual Studio 2019似乎已从Xamarin.Forms跨平台项目创建中删除了UWP模板.

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

推荐答案

4月9日更新:发布了2019年的新版本,再次恢复了UWP模板

从VS2019中删除UWP模板是正确的,我不知道其背后的原因,但我们必须对其进行处理.但是,有一个 页面可以逐步引导您完成整个过程.在Visual Studio for Mac中创建的项目已经存在了一段时间,这些项目也不包含UWP模板.完整的描述可以在这里找到: https://docs.microsoft.com/zh-cn/xamarin/xamarin-forms/platform/windows/installation/从此页面获取:

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://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/windows/installation/ taken from this page:

首先,右键单击解决方案,然后选择添加>新建项目... ,然后添加一个空白应用程序(通用Windows)项目:

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

然后,选择最低和目标UWP版本.

Then, select the minimum and targeted UWP versions.

右键单击UWP项目,然后选择管理NuGet程序包... ,然后添加 Xamarin.Forms 程序包.确保解决方案中的其他项目也已更新为Xamarin.Forms包的相同版本.

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.

此外,请确保新的UWP项目将在 Build> Configuration Manager窗口中构建(默认情况下可能不会发生).选中通用项目的 Build Deploy 框:

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:

右键单击UWP项目,然后选择 Add> Reference ,然后创建对Xamarin.Forms应用程序项目(.NET Standard或Shared Project)的引用.

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).

在UWP项目中,编辑App.xaml.cs,以将Init方法调用包括在第52行的OnLaunched方法内部:

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

在UWP项目中,通过删除Page元素中包含的Grid来编辑MainPage.xaml.然后在MainPage.xaml中,为Xamarin.Forms.Platform.UWP添加一个新的xmlns条目,如下所示:xmlns:forms="using:Xamarin.Forms.Platform.UWP".

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".

MainPage.xaml中,更改根<Page element to <forms:WindowsPage,如下所示:

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

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

在UWP项目中,编辑MainPage.xaml.cs以删除类名称的Page继承说明符(由于由于上一步所做的更改,它现在将从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"

MainPage.xaml.cs中,在MainPage构造函数中添加LoadApplication调用以启动Xamarin.Forms应用程序:

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.

这篇关于VS2019 + Xamarin.Forms = UWP/EXE掉线了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆