【问题标题】:Xamarin Forms MacOS and NetStandardXamarin 形成 MacOS 和 NetStandard
【发布时间】:2017-12-29 20:20:37
【问题描述】:

我刚开始研究这个问题,遇到了一个问题,阻止我运行我的 MacOS 应用程序。我已按照这篇博文中详述的所有步骤进行操作:

https://blog.xamarin.com/preview-bringing-macos-to-xamarin-forms/

使用以下说明将 XAML 所在的 Xamarin Forms 项目从 PCL 更改为 NetStandard 项目:

https://blog.xamarin.com/building-xamarin-forms-apps-net-standard/

但由于某种原因,它声称找不到我的 App 类。尽管它在设计时被发现并被着色,就好像它是一种类型,它甚至在智能感知中作为一个类出现。当我编译项目时,它会出错:

MacOS/AppDelegate.cs(40,40):错误 CS0234:命名空间“Oracle”中不存在类型或命名空间名称“App”(您是否缺少程序集引用?) (CS0234) (Oracle.MacOS )

绝对不会像在智能感知中那样作为程序集引用丢失。还有人看到这个吗?问题是什么?有没有办法解决这个问题?

App.Xaml.cs

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Oracle
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            SetMainPage();
        }

        public static void SetMainPage()
        {
            Current.MainPage = new TabbedPage
            {
                Children =
                {
                    new NavigationPage(new ItemsPage())
                    {
                        Title = "Browse",
                        Icon = Device.OnPlatform<string>("tab_feed.png",null,null)
                    },
                    new NavigationPage(new AboutPage())
                    {
                        Title = "About Test",
                        Icon = Device.OnPlatform<string>("tab_about.png",null,null)
                    },
                }
            };
        }
    }
}

AppDelegate.cs

[Register("AppDelegate")]
public class AppDelegate : FormsApplicationDelegate
{
    NSWindow _window;
    public AppDelegate()
    {
        var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;

        var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
        _window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
        _window.Title = "Xamarin.Forms on Mac!";
        _window.TitleVisibility = NSWindowTitleVisibility.Hidden;
    }

    public override NSWindow MainWindow
    {
        get { return _window; }
    }

    public override void DidFinishLaunching(NSNotification notification)
    {
        Forms.Init();
        LoadApplication(new Oracle.App());
        base.DidFinishLaunching(notification);
    }

    public override void WillTerminate(NSNotification notification)
    {
        // Insert code here to tear down your application
    }
}

更新 经过一番修补,我已经解决了第一个问题,现在我看到了

错误 MM0023:应用程序名称“Oracle.exe”与另一个用户程序集冲突。 (MM0023) (Oracle.MacOS)

【问题讨论】:

  • 请显示您的App.csAppDelegate.cs 文件中的一些代码。另外,您是否尝试过清理项目,从所有项目文件中删除 binobj 文件夹并重新构建?如果您要进行此类重大更改,这有时可能会有所帮助。
  • 好电话,已更新。已重新清理、重建,但我还没有手动删除......为什么我不认为尝试这超出了我的范围!!
  • 在您的App.xaml.cs 中,命名空间是什么?真的是Oracle吗?
  • 是的。我已经更新了代码 sn-p 以包含命名空间声明。
  • 我已经解决了这个命名空间问题,现在我看到另一个错误/Users/jamesgreen/Development/GitHub/Oracle/Oracle.MacOS/MMP: Error MM0023: Application name 'Oracle.exe' conflicts with another user assembly. (MM0023) (Oracle.MacOS),这似乎与构建过程本身的问题有关forums.xamarin.com/discussion/92773/…

标签: c# macos xamarin.forms .net-standard


【解决方案1】:

3 年后.. 但今天我尝试为 mac 创建我的第一个 xamarin 表单应用程序并遇到了同样的错误。 要重现此错误,您需要 2 个项目,例如“MyApp”(网络标准)和“MyApp.Mac”(Xamarin.Mac)。

要修复它,您需要:

  1. 将共享项目从“MyApp”重命名为“MyApp.Shared”。
  2. 检查共享项目的属性。名称和默认命名空间应为“MyApp.Shared”。
  3. 删除从 mac 项目到共享项目的链接。
  4. 再次添加共享项目的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多