我正在尝试在.NET Core下使用Mono.Options
,并使用它的命令行工具。
我最初尝试通过在project.json
文件中声明依赖关系,从NuGet加载它,但是dotnet restore
抱怨该包与dnxcore50
框架不兼容。²
因此,我决定尝试从源代码构建它。我在Mono.Options
源代码中注意到它有一个PCL
构建选项。想着PCL可能是一个足够接近.NET Core的近似版本,我尝试创建了一个启用该设置的DLL项目来构建它:
{
"version": "0.0.0-d95ccb2ca5",
"compilationOptions": {
"emitEntryPoint": false,
"define": [ "PCL" ],
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811"
},
"compile": [ "*.cs" ],
"frameworks": {
"dnxcore50": { }
}
}
我将从上面链接下载的 Options.cs
文件副本放置在同一目录下并输入 dotnet build
命令,结果出现以下错误:
.../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?)
我有几个问题:
...还有其他一些错误都源自这两个关键错误。
Why is
System.Runtime.Serialization
missing? According to the docs, it is supposed to be part of .NET Core.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 aboutSerialization
continues to occur. Is .NET Core simply incomplete at this time?Is there a workaround other than just waiting for this class to be ported over?
I used
dnxcore50
in the initial project file because that's howdotnet new
generated it. The change todotnet5.4
seems to be necessary according to the ASP.NET 5 package search engine, but is that change kosher with .NET Core?³
侧记
为什么? 因为现在是 2016 年,然而 .NET 仍未加入命令行选项解析。真让人恼火。或许微软收购 Xamarin 将会使
Mono.Options
被包含进 .NET Core 中。与此同时...Mono.Options
4.2.2.1 — 在这个问题被提出后发布 — 解决了这个兼容性问题。ASP.NET 5 的软件包搜索结果表明
netcore50
也应该对我的目的有效,但随后我收到有关no run-time assembly compatible with osx.10.10-x64
的投诉。这是在一台安装了 Mono 4.2.1 的 OS X 10.10 机器上发生的。很显然,
Mono.Options
确实可以在该版本下构建。我提出了这个问题是因为我正在尝试将一些更简单的现有项目切换到这个新的、更轻量级的运行时。