.Net Standard 2.0 构建在 Teamcity 上失败

.Net Standard 2.0 build fails on Teamcity

我正在将一个项目转换为新的 .csproj 格式并将其设置为以 netstandard2.0 和 net45 为目标。它在我的机器上运行良好,但在尝试为 netstandard2.0 构建时在我们的构建服务器上以某种方式失败。 net45 的构建运行没有错误。部分日志:

C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\bin\Roslyn\csc.exe <lots of parameters>
Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\bin\Roslyn
error CS0234: The type or namespace name 'Serialization' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'BinaryFormatter' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ICloneable' could not be found (are you missing a using directive or an assembly reference?)

我知道这些类型在 2.0 版之前不存在,但不清楚它是如何找不到它们的。 .Net Core 2.0 SDK 似乎安装在构建服务器上,此外我尝试 运行 使用较低版本的 SDK,它明确告诉我要针对不同版本的标准。据我所知,自 2.0 版本以来,项目文件中不再需要对标准库的显式依赖。

这些错误的原因可能是什么?

我们使用 Teamcity MsBuild build runner 的 MsBuild 脚本 运行,ToolsVersion=15.0。

好吧,我好像自己想出了答案。

MsBuild runner 使用作为 Visual Studio 的一部分安装的 SDK 进行构建,而 VS 仅在版本 15.3 中添加了对 .NET Core 2.0 SDK 的适当支持。构建服务器上安装了一些早期版本。这些错误是由于它无法解析正确的 SDK 而使用旧版本的 dll 而引起的。传递给编译器的参数之一(注意标准的版本):reference:C:\Users\buildserver\.nuget\packages\system.runtim‌​e.3.0\ref\netstand‌​ard1.5\System.Runtim‌​e.dll /.

解决此问题的一种方法是在构建服务器上将 Visual Studio 更新为 15.3。我在 .

中找到了解决方法

您只能安装 Visual studio 2017 构建工具

(https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15