visual-studio - 添加内容页面 VS 时出现 Xamarin System.Exception

标签 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.

添加文件时,我执行以下操作:
Right click on Views in my Xamarin Solution > Add > New Item > Content Page > Add
在 windows 资源管理器中查看时,创建了一个文件 MyPage.xaml但它没有创建 MyPage.xaml.cs它没有添加到解决方案中

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

这让我发疯,因为我什至无法添加一页

作为一种解决方法,我使用 W. 资源管理器手动添加文件,然后手动编辑 app.projitems,但这太荒谬了。

最佳答案

在解决此问题之前,作为一种肮脏的解决方法,将文件“手动”添加到项目中即可完成工作。

在 Visual Studio 关闭的情况下,

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

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

    关于visual-studio - 添加内容页面 VS 时出现 Xamarin System.Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47738138/

    相关文章:

    macos - xamarin for mac 无法创建或打开 xamarin.form 项目

    ios - 如何为 Xamarin.iOS 创建绑定(bind)?

    android - 是否有适用于 iOS 和 Android 的 Xamarin.Form MediaPlayer?

    c# - Xamarin 表单切换按钮在 IOS 上的默认颜色

    css - 如何在 Xamarin 中使用 CSS 设置自定义字体系列

    C# 无法捕获 StackOverflowException 或查看它发生的位置

    asp.net - 在 VS 中附加到工作进程的更快方法

    c# - 如何在 Xamarin.Forms ListView 下添加按钮

    visual-studio - TFS 2010 Web 访问构建摘要中缺少 "View Test Results"?

    visual-studio - 防止在 NuGet content 和 contentFiles 文件夹中复制文件