.Net标准2.0构建在Teamcity上失败

问题描述:

我正在将项目转换为新的.csproj格式,并将其设置为同时针对netstandard2.0和net45。它在我的机器上运行良好,但是在尝试构建netstandard2.0时,在构建服务器上失败。 net45的构建无错地运行。部分日志:.Net标准2.0构建在Teamcity上失败

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\Roslyn\csc.exe <lots of parameters> 
Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.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。

+0

是一个的NuGet恢复到的MSBuild调用之前执行(例如'的MSBuild /吨:Restore') –

+0

是的,我们使用内置在解决方案文件中的MsBuild目标'恢复'它在我的机器上的一个干净的回购做所有的工作 – holdn

+0

“很多参数”是否包含对'netstandard.dll'的引用?至少应该定义ICloneable在那里 –

好吧,我似乎已经自己想出了答案。

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

解决此问题的一种方法是将Visual Studio更新到构建服务器上的15.3。我在this answer中解决了这个问题。