問題描述
我想在我的項目中使用 C# 6(空傳播,其他功能).
I want to use C# 6 in my project (null propagation, other features).
我已經在我的 PC 上安裝了 VS 2015,它運行良好,可以構建類似的測試代碼
I've installed VS 2015 on my PC and it works brilliantly and builds test code like
var user = new SingleUserModel(); //all model fields are null
var test = user.User?.Avatar?["blah"];
但是當我將我的項目推送到 repo 并且 CI 開始構建它時,由于 ?
不受支持,構建失敗.
But when I push my project to the repo and CI starts to build it, build fails because of unsupported ?
.
我也在 CI 服務器上安裝了 VS2015,但看起來它并沒有使用它.我能做什么?
I've installed VS2015 on CI server too but looke like it doesn't use it. What can I do?
CI - CruiseControl .NET使用 C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
CI - CruiseControl .NET
Builds with C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
推薦答案
一定要調用:
C:Program Files (x86)MSBuild14.0BinMsBuild.exe
這是 Visual Studio 2015 附帶的 MsBuild 版本,它調用理解這一點的 C# 編譯器.您可以通過安裝任何版本的 Visual Studio 2015 或安裝獨立的 Microsoft 構建工具 2015.
That's the version of MsBuild that ships with Visual Studio 2015 and calls the C# compiler that understands this. You can get this version of MsBuild on your system by installing any edition of Visual Studio 2015 or by installing the stand-alone Microsoft Build Tools 2015.
添加對以下 NuGet 包的引用也會強制使用新編譯器:
Adding a reference to the following NuGet package will also force use of the new compiler:
Install-Package Microsoft.Net.Compilers
請注意,Install-Package
將選擇最新的可用版本,它可能不是您正在尋找的版本.在安裝之前,請檢查發行說明和依賴項以解決正在處理的版本的潛在問題,在這種情況下,它更特定于 VS 2015.
Please note Install-Package
will pick the latest available version which may not be the one you are looking for. Before you install, please check the release notes and dependencies to resolve the underlying issue with the version being dealt with, which in this case, was more specific to VS 2015.
所以對于 Visual Studio 2015:
So for Visual Studio 2015:
Install-Package Microsoft.Net.Compilers -Version 1.0.0
這篇關于如何將 msbuild 升級到 C# 6?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!