Xamarin forms visual studio for Mac clean-namespace 问题

Xamarin forms visual studio for Mac clean-namespace problem

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

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 />

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

请帮忙

其实这个问题很常见是因为你的项目没有正确编译,或者在编译 bin 和 obj 后缺少这个 class 这很好。

解决方案:

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

  • 现在根据依赖单独构建所有项目,即如果您有四个项目 A、B、iOS 和 Android,并且 B 依赖于 A,即它有一个引用 A 然后您将首先清理构建 A,然后清理 B,然后清理 iOS 和 Android.

  • 中的任何一个
  • 如果在此之后您的问题仍未解决,那么您可能需要一起重新启动 VS

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

祝你好运

对不起...我做错了...一个真正的错误。

我在程序集属性中键入了“:”而不是“=”。

应该是 xmlns:controls=“clr-命名空间:MyProject.Shared.Renderer:assembly=MyProject.Shared”