2017-10-06 126 views
0

我正在將項目轉換爲新的.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在那裏 –

回答

1

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

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中解決了這個問題。