How to upgrade msbuild to C# 6?(如何将 msbuild 升级到 C# 6?)
问题描述
我想在我的项目中使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 msbuild 升级到 C# 6?


基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01