Building Mono.Options under .NET Core CLI (dotnet build)

Viewed 1284

I'm trying to use Mono.Options under .NET Core,¹ using its command-line tools.

I initially tried loading it from NuGet using a dependency declaration in my project.json file, but dotnet restore complains that the package is not compatible with the dnxcore50 framework.²

I therefore decided to try building it from source. I noticed in the Mono.Options source code that it has a PCL build option. Thinking that maybe PCL was a close-enough approximation to .NET Core, I tried creating a DLL project to build it with that setting enabled:

{
    "version": "0.0.0-d95ccb2ca5",
    "compilationOptions": {
        "emitEntryPoint": false,
        "define": [ "PCL" ],
    },

    "dependencies": {
        "NETStandard.Library": "1.0.0-rc2-23811"
    },

    "compile": [ "*.cs" ],

    "frameworks": {
        "dnxcore50": { }
    }
}

I then placed a copy of Options.cs downloaded from the link above in the same directory and said dotnet build, which gives these errors:

.../Mono/Options.cs(137,22): error CS0234: The
type or namespace name 'Serialization' does not exist in the namespace
'System.Runtime' (are you missing an assembly reference?)
.../Mono/Options.cs(729,27): error CS0246: The
type or namespace name 'KeyedCollection<,>' could not be found (are you
missing a using directive or an assembly reference?)

...plus several others all stemming from those two key errors.

That finally brings me to my questions:

  1. Why is System.Runtime.Serialization missing? According to the docs, it is supposed to be part of .NET Core.

  2. I later added explicit dependencies for the parent packages of the two namespaces the compiler is complaining about:

    ...
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "System.ObjectModel": "4.0.*",
                "System.Runtime": "4.1.0-rc2-23811"
            }
        }
    }
    

    dotnet restore then succeeds, and most of the build errors go away, but the first error about Serialization continues to occur. Is .NET Core simply incomplete at this time?

  3. Is there a workaround other than just waiting for this class to be ported over?

  4. I used dnxcore50 in the initial project file because that's how dotnet new generated it. The change to dotnet5.4 seems to be necessary according to the ASP.NET 5 package search engine, but is that change kosher with .NET Core?³


Asides

  1. Why? Because it's 2016 and .NET still doesn't have command-line option parsing built-in. Grrrr. Maybe Microsoft's acquisition of Xamarin will result in Mono.Options being included in .NET Core. Meanwhile...

  2. Mono.Options 4.2.2.1 — released after this question was asked — solves this compatibility problem.

  3. The ASP.NET 5 package search results imply that netcore50 should also work for my purposes, but then I get complaints about no run-time assembly compatible with osx.10.10-x64.

    This is happening on an OS X 10.10 machine with Mono 4.2.1 installed. Mono.Options does build under that, obviously. This question came up because I'm trying to switch some of my simpler existing projects to this new, lighter runtime.

3 Answers
Related