首页 > 解决方案 > Xamarin 为 Mac 干净命名空间问题形成 Visual Studio

问题描述

我使用 .net 标准创建了一个 Xamarin 表单应用程序。然后,我在解决方案中添加了一个 .net 标准库项目,其中将包括常见代码,例如渲染、行为等。我通过右键单击依赖项和 Edit References 菜单,将通用 .net 标准库项目的引用包含到主 Xamarin 表单项目中. 最后,我尝试通过使用 Xamarin.Forms 指定以下行,在主要 Xamarin 表单的内容页面上包含渲染器文件的命名空间;

namespace MyProject.Shared.Renderer
{
    public class ExtendedEntry : Entry
    {
        public static readonly BindableProperty IsBorderErrorVisibleProperty = BindableProperty.Create(nameof(IsBorderErrorVisible), typeof(bool), typeof(ExtendedEntry),
            false, BindingMode.TwoWay);

        public bool IsBorderErrorVisible
        {
            get { return (bool)GetValue(IsBorderErrorVisibleProperty); }
            set { SetValue(IsBorderErrorVisibleProperty, value); }
        }

        public static readonly BindableProperty BorderErrorColorProperty = BindableProperty.Create(nameof(BorderErrorColor), typeof(Color), typeof(ExtendedEntry),
            null, BindingMode.TwoWay);

        public Color BorderErrorColor
        {
            get { return (Color)GetValue(BorderErrorColorProperty); }
            set { SetValue(BorderErrorColorProperty, value); }
        }

        public static readonly BindableProperty ErrorTextProperty = BindableProperty.Create(nameof(ErrorText), typeof(string), typeof(ExtendedEntry), string.Empty,
            BindingMode.TwoWay);

        public string ErrorText
        {
            get { return (string)GetValue(ErrorTextProperty); }
            set { SetValue(ErrorTextProperty, value); }
        }
    }
}
xmlns:controls=“clr-namespace:MyProject.Shared.Renderer:assembly:MyProject.Shared”

Then I reference the control as
<controls:ExtendedEntry />

但这会产生构建错误,提示在程序集 MyProject.Shared 中找不到 ExtendedEntry

请帮忙

标签: xamarin.formsxamarin.androidxamarin.iosxamarin-studio.net-standard

解决方案


好吧,实际上这个问题很常见,因为您的项目没有正确编译,或者在编译 bin 和 obj 之后缺少这个类,这很好。

解决方案:

  • 从解决方案中的所有项目中删除所有 bin obj 文件夹。

  • 现在根据依赖关系单独构建所有项目,即如果您有四个项目 A、B、iOS 和 Android 并且 B 依赖于 A 即它具有对 A 的引用,那么您将首先清理构建 A 然后 B 然后在 iOS 和安卓。

  • 如果即使在此之后您的问题仍未解决,那么您可能希望一起重新启动 VS

如果您仍然遇到此问题,请随时恢复。

祝你好运


推荐阅读