问题描述
我想在我的项目中使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!