如何将 msbuild 升级到 C# 6?
- 作者: 蝴蝶之舞飞啊飞
- 来源: 51数据库
- 2023-02-13
问题描述
我想在我的项目中使用 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
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源









