简体   繁体   English

TeamNetity上的.Net Standard 2.0构建失败

[英].Net Standard 2.0 build fails on Teamcity

I am converting a project to the new .csproj format and setting it up to target both netstandard2.0 and net45. 我正在将项目转换为新的.csproj格式,并将其设置为netstandard2.0和net45。 It's working fine on my machine, but somehow fails on our build server when trying to build for netstandard2.0. 它在我的机器上工作正常,但在尝试构建netstandard2.0时,在我们的构建服务器上失败了。 The build for net45 runs without errors. net45的构建运行没有错误。 Part of the log: 部分日志:

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?)

I am aware that these types did not exist prior to version 2.0, but it is unclear how it fails to find them. 我知道这些类型在2.0版之前不存在,但目前还不清楚它是如何找不到它们的。 .Net Core 2.0 SDK seems to be installed on the build server, besides I tried running it with lower versions of the SDK and it explicitly told me to target a different version of the standard. .Net Core 2.0 SDK似乎安装在构建服务器上,除了我尝试使用较低版本的SDK运行它,它明确地告诉我要针对不同版本的标准。 As far as I know, since version 2.0 there's no need for explicit dependencies on the standard library in the project file. 据我所知,自2.0版以来,不需要对项目文件中的标准库进行显式依赖。

What could be the reason of these errors? 这些错误可能是什么原因?

We use an MsBuild script ran by Teamcity MsBuild build runner with ToolsVersion=15.0. 我们使用Teamcity MsBuild构建运行器运行的MsBuild脚本,ToolsVersion = 15.0。

Ok, I seem to have figured the answer myself. 好吧,我似乎已经找到了答案。

MsBuild runner uses SDK installed as part of Visual Studio to build, and VS only adds proper support for .NET Core 2.0 SDK in version 15.3. MsBuild runner使用安装的SDK作为Visual Studio的一部分进行构建,VS仅在15.3版中为.NET Core 2.0 SDK添加了适当的支持。 Some earlier version was installed on the build server. 一些早期版本安装在构建服务器上。 The errors were caused by it being unable to resolve the correct SDK and using dlls from the older versions instead. 错误是由于它无法解析正确的SDK并使用旧版本的dll而引起的。 One of the parameters passed to the compiler (note the version of the standard): reference:C:\\Users\\buildserver\\.nuget\\packages\\system.runtim‌​e\\4.3.0\\ref\\netstand‌​ard1.5\\System.Runtim‌​e.dll / . 传递给编译器的其中一个参数(注意标准版本): reference:C:\\Users\\buildserver\\.nuget\\packages\\system.runtim‌​e\\4.3.0\\ref\\netstand‌​ard1.5\\System.Runtim‌​e.dll /

One way to solve this would be to update Visual Studio to 15.3 on the build server. 解决此问题的一种方法是在构建服务器上将Visual Studio更新为15.3。 I got out with the workaround in this answer . 我在这个答案中找到了解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM