【问题标题】:Xamarin Cross-Platform App Solution Build failed?Xamarin 跨平台应用解决方案构建失败?
【发布时间】:2019-01-30 15:54:08
【问题描述】:

我对 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”。等等。

如何解决这个问题?我将非常感谢。

谢谢。

【问题讨论】:

  • 错误信息是什么?
  • 如果您的构建失败,应该有一些解释性错误消息告诉您原因。还有Text:"Say Hello !"是无效的,你的意思是Text="Say Hello !"
  • 命名空间'System'的类型没有被引用等等......@Joe Seweli
  • Cicked="Button_Clicked",除了Clicked属性拼写错误,其余代码看起来正常。

标签: c# xamarin.forms


【解决方案1】:

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

您可能需要:

  • 清理项目
  • 恢复 Nuget 包

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2018-04-28
    • 2020-05-02
    • 1970-01-01
    相关资源
    最近更新 更多