添加内容页面VS时的Xamarin System.Exception

Maz*_*zzy 8 visual-studio xamarin xamarin.forms

尝试Content Page在visual studio中添加解决方案时,会发生以下错误:

Exception of type 'System.Exception' was thrown.

The project system has encountered an error.

Did not find new element in the hierarchy for item `Views\MyPage.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.
Run Code Online (Sandbox Code Playgroud)

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

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

查看Windows资源管理器时,会创建一个文件,MyPage.xaml但尚未创建MyPage.xaml.cs,并且未将其添加到解决方案中

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

它让我疯狂,因为我甚至无法添加单页

作为一种解决方法,我使用W. explorer手动添加文件,然后手动编辑app.projitems,但这简直太荒谬了.

The*_*rst 6

作为一个肮脏的解决方法,直到解决这个问题,将"手动"文件添加到项目中可以完成工作.

关闭Visual Studio,

  1. 复制/粘贴现有​​(工作)*.xaml和*.xaml.cs文件(根据需要重命名)
  2. 使用文本编辑器(而非VS)打开新粘贴的文件,并将内容重命名为#1中所选的名称
  3. 将新粘贴的文件添加到*.projitems文件中(在文本编辑器中打开它,搜索您在#1中复制的文件名并添加新的文件名) - 将有3个地方添加它们

现在在VS中打开解决方案并重建 - 它应该看起来和构建正常.