2

This guide explains how to create a console app that uses Xamarin.Mac APIs. The trick is to reference Xamarin.Mac.dll and link libxammac.dylib in your project. But it is limited to the Mono runtime (pre-.NET-Core).

With .NET 6, there are now workloads and a new net6.0-macos target runtime. However, this seems to assume that you are creating a GUI app rather than a console app.

When installing the workload in .NET 6, it seems to only install a reference assembly for Xamarin.Mac.dll. So where is the real Xamarin.Mac.dll for .NET 6? And is it possible to use it without targeting net6.0-macos?

David Lechner
  • 1,433
  • 17
  • 29

1 Answers1

1

I was able to get a console app to run following this example.

The main point is that .csproj needs to contain:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0-macos</TargetFramework>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>osx-x64</RuntimeIdentifier>
  </PropertyGroup>

And there needs to be an info.plist file in the project directory.

It isn't quite what I was hoping for since it still creates a .app bundle and dotnet run doesn't actually run the app. You have to manually run bin/Debug/net6.0-macos/osx-x64/MyProject.app/Contents/MacOS/MyProject.


Answering the question about where the real Xamarin.Mac.dll and associated native libraries live: it appears to be in the Microsoft.macOS.Runtime.osx-x64 NuGet package. However, this isn't a normal package that can be referenced from a project.

David Lechner
  • 1,433
  • 17
  • 29