I am converting a project to the new .csproj
format and setting it up to target both netstandard2.0 and net45. It's working fine on my machine, but somehow fails on our build server when trying to build for netstandard2.0. The build for net45 runs without errors. 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. .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. As far as I know, since version 2.0 there's no need for explicit dependencies on the standard library in the project file.
What could be the reason of these errors?
We use an MsBuild script ran by Teamcity MsBuild build runner with 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. 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. One of the parameters passed to the compiler (note the version of the standard): reference:C:\Users\buildserver\.nuget\packages\system.runtime\4.3.0\ref\netstandard1.5\System.Runtime.dll /
.
One way to solve this would be to update Visual Studio to 15.3 on the build server. I got out with the workaround in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With