将 PCL 升级到 .NET Standard 2.0 后在 Mac 上生成错误

Build error on Mac after upgrading PCL to .NET Standard 2.0

upgraded 我的独立 PCL 库要使用 .Net Standard 2.0。现在我尝试在 Mac 上构建,但出现以下错误:

XamlC:
  Compiling Xaml, assembly: obj/Release/netstandard2.0/MyLibrary.dll
  "obj/Release/netstandard2.0/XamlC.stamp" wird erstellt, da "AlwaysCreate" angegeben wurde.
GenerateSatelliteAssemblies:
  Das Verzeichnis "obj/Release/netstandard2.0/de" wird erstellt.
  /Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/4.5/al.exe /culture:de /out:obj/Release/netstandard2.0/de/MyLibrary.resources.dll /template:obj/Release/netstandard2.0/MyLibrary.dll /embed:obj/Release/netstandard2.0/MyLibrary.Common.Localization.LibResources.de.resources
/usr/local/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: Unerwarteter Fehler bei der GenerateDepsFile-Aufgabe. [/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary/MyLibrary.csproj]
/usr/local/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) [/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary/MyLibrary.csproj]
/usr/local/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <a7945d89c0ac41f8a1c76203a2991e34>:0  [/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary/MyLibrary.csproj]
/usr/local/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0  [/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary/MyLibrary.csproj]
/usr/local/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x00212] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0  [/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary/MyLibrary.csproj]
Die Erstellung des Projekts "/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary/MyLibrary.csproj" ist abgeschlossen (Standardziele) -- FEHLER.
Die Erstellung des Projekts "/Users/someuser/.jenkins/workspace/MyLibrary/MyLibrary.sln" ist abgeschlossen, Build Ziel(e) -- FEHLER.

Fehler beim Buildvorgang.

如您所见,我正在使用 Jenkins 进行构建,但这根本不应该是问题所在(使用了 msbuild)。这个问题似乎是 known issue,但我不知道在给定的情况下如何解决它(使用旧版本的 Visual Studio for Mac)。这些是使用的版本:

=== Visual Studio Community 2017 for Mac ===

Version 7.8.4 (build 1)
Installation UUID: 3d97ef3f-5e3c-496d-bba3-bf410eac83a0
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 5.0.0.0 ( / b40230c0)

    Package version: 518000268

=== Mono Framework MDK ===

Runtime:
    Mono 5.18.0.268 (2018-08/68aad3b0eb7) (64-bit)
    Package version: 518000268

=== NuGet ===

Version: 4.8.2.5835

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.11
    2.1.9
    2.1.2
    2.1.1
    2.0.5
    2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.700/Sdks
SDK Versions:
    2.1.700
    2.1.505
    2.1.302
    2.1.301
    2.1.4
    2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.10
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 9.3.0.23 (Visual Studio Community)
Android SDK: /Users/someuser/Library/Android/sdk
    Supported Android versions:
        4.4    (API level 19)
        4.4.87 (API level 20)
        5.0    (API level 21)
        5.1    (API level 22)
        6.0    (API level 23)
        7.0    (API level 24)
        7.1    (API level 25)
        8.0    (API level 26)
        8.1    (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 27.0.1

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/someuser/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.8.1.0
Hash: 8924ea4a

=== Apple Developer Tools ===

Xcode 10.2.1 (14490.122)
Build 10E1001

=== Xamarin.Mac ===

Version: 5.10.0.157 (Visual Studio Community)
Hash: 6bd94753
Branch: d16-1
Build date: 2019-06-12 17:28:48-0400

=== Xamarin.iOS ===

Version: 12.4.0.64 (Visual Studio Community)
Hash: 9c8d8e0a
Branch: xcode10.2
Build date: 2019-03-27 06:24:31-0400

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 708040001
Git revision: 9e1629d19c3f9f6d11a5d9895993a8edf1e7a3aa
Build date: 2019-05-10 19:37:45+00
Build branch: release-7.8
Xamarin extensions: c3cb4059acaf9142b2a5c176866edfc4c32b7da2

=== Operating System ===

Mac OS X 10.14.6
Darwin 18.7.0 Darwin Kernel Version 18.7.0
    Thu Jun 20 18:42:21 PDT 2019
    root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64

我应该执行哪些步骤才能使构建再次运行?除了更新到 Visual Studio 2019 for Mac (v. 8+)?升级到更新的 Mono 版本(哪个版本?)就足够了吗?这仍然适用于我的设置吗?

现在我可以解决问题了。感谢 post from AndreyAkinshin 我已经修复了它。

使用 dotnet --list-sdks 我得到了 2.1.700 作为最新版本。引用 source:

In case, you use mono 5.x and you want to continue using it, you need to change the .NET Core SDK version. It is recommended to use .NET Core SDK 2.1.5xx or 2.2.1xx (for example, 2.1.505 or 2.2.108).

我只需要 uninstall .NET Core 2.1.700

sudo rm -rf /usr/local/share/dotnet/sdk/2.1.700

后来我查看了dotnet --version,我目前使用的版本是2.1.505。还可以使用其他一些选项,如 here.

所述