Xamarin System.Exception添加内容页面vs



尝试在Visual Studio中的解决方案中添加Content Page时,发生以下错误:

Exception of type 'System.Exception' was thrown.
The project system has encountered an error.
Did not find new element in the hierarchy for item `ViewsMyPage.xaml`.
The item would have been added with type "Page".
The project item schema service knows about this item type.
The item does exist in the project file.

添加文件时,我要执行以下操作:

Right click on Views in my Xamarin Solution > Add > New Item > Content Page > Add

在Windows Explorer中查看时,有一个文件创建的MyPage.xaml,但尚未创建MyPage.xaml.cs,也没有将其添加到解决方案

这是一个空白的Xamarin共享项目,此错误一直在发生...

这让我发疯,因为我甚至无法添加一个页面

作为解决方法,我使用W. Explorer手动添加文件,然后手动编辑App.projitems,但这只是荒谬的。

作为肮脏的解决方法,直到修复此操作,将文件"手动"添加到项目中。

随着视觉工作室的关闭,

  1. 复制/粘贴现有(工作) *.xAML和 *.xaml.cs文件(重命名他们随心所欲)
  2. 用文本打开新粘贴的文件编辑器(不是vs),并将其重命名为您所选名称的内容
  3. 将新粘贴的文件添加到您的 *.projitems文件(在文本中打开编辑,搜索您在#1中复制的文件名并添加新的文件名同样的) - 将有3个添加的地方

现在打开VS和重建的解决方案 - 它应该看起来并构建良好。

显然,如果您进入VS2017安装程序并安装Universal Windows Platform(UWP)开发工作负载,这将解决问题。

确保您有stacklayout代替contentpage.content在您的.xAML文件中,在vs。

最新更新