ctacke
ctacke

Reputation: 67178

Visual Studio and NuGet targeting Mono on Linux

I build a lot of packages that have cross-platform targeting. I like using NuGet as a deployment for all of the obvious reasons, but I'm having difficulty understanding how I target a specific binary for Mono on Linux.

As an example I have a library that, in the Mono for Linux version, references `Mono.Posix.Helper.dll. This is very specific to Mono on Linux. It's not for the desktop. It's not for Mono on Android or Mono on iOS. The same library has different implementations for .NET of the desktop, .NET on Windows CE, Mono on Android and Mono on iOS.

It seems that I need two things, neither of which I can seem to find:

  1. A way to tell NuGet that a specific set of binaries targets Mono on Linux. I see nothing in the official documentation of the NuGet schema target frameworks.
  2. A way to tell Visual Studio that my project that will consume those binaries targets Mono on Linux. I've found this nice list of project GUIDs but, of course, there's nothing in there for Mono that isn't targeting Android or iOS.

Right now I'm solving this with a less-than-friendly post-build task, but that's really not fun when I need to create a new project that uses one of these packages.

I know Microsoft has been trying to get more Linux-friendly over the past few years, but this seems like a pretty big hole. I can't be the only person out here that's building code for Mono on Linux, can I? What's the solution here?

Upvotes: 0

Views: 285

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100581

Currently, this isn't possible.

NuGet (3.*, 4) does have a concept of "runtimes" but those are referring to the operating system that the "runtime" runs on. So while you can have a specific asset for linux-x64, this cannot tell if you are on mono or .net core. In fact, even when you use a net461 target framework with a runtimes/linux-x64/lib/net461/linux-specific.dll file, this may even be used in a .NET Core 2.0 app since .NET Core 2.0 can use net461+ libraries.

The only way this is currently possible is to have managed shim that resolves the right assembly on runtime. This would also make the consuming project "portable" - meaning it can be run on windows directly and on linux through mono, assuming all libraries can be loaded dynamically.

Upvotes: 1

Related Questions