Xamarin跨平台应用程序解决方案构建失败?

时间:2019-01-29 15:06:16

标签: c# xamarin.forms

我对Xamarin表格绝对陌生。我认为我要问的问题不会太好,但是我遇到的问题非常奇怪,我不知道如何解决。

问题: 我在Visual Studio 2017中创建了一个全新的跨平台项目。 并写了一些代码,当我运行我的应用程序时,构建解决方案失败了。

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:HelloWorld"
             x:Class="HelloWorld.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <Label x:Name="_label"  Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />

        <Entry x:Name="EnterYourName" Placeholder="Write your name"/>
        <Button Text="Say Hello !" Clicked="Button_Clicked" />

    </StackLayout>

</ContentPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Form;

namespace HelloWorld
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        void Button_Clicked(object sender, EventArgs e)
        {
            _label.Text = "Welcome" + " " + EnterYourName.Text; 
        }
    }
}

错误:

  

全部包括必要的using语句,当我单击时   在构建解决方案上,它给我这个错误...

  • 找不到类型或名称空间名称“系统”(您是否丢失了 using指令或程序集参考。)
  • 找不到类型或名称空间名称“ Xamarin”(您丢失了吗? using指令或程序集参考。)
  • 未定义或导入“ System.Void”预定义类型。等等。

如何解决此问题?我会非常感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

这个项目很好,所以问题与代码无关(除非您在App.Xaml和App.Xaml.cs中有奇怪的地方)。

您可能需要:

  • 清理项目
  • 还原Nuget软件包

如果问题仅出现在单个平台上,则可能需要检查与Mac的连接或查看是否已安装所有必需的Android SDK /组件。