简体   繁体   English

自从切换到VS 2015并使用C#6 Roslyn功能以来,Visual Studio Online CI的每日构建失败

[英]Visual Studio Online CI daily builds fail since switching to VS 2015 and using C# 6 Roslyn features

Since switching from VS 2013 to VS 2015 and using some new C# 6 features, our daily builds in Visual Studio Online have begun failing. 自从VS 2013切换到VS 2015并使用了一些新的C# 6功能以来,我们在Visual Studio Online日常构建已开始失败。

The errors on the build are all pointing to the new auto property feature but I assume all new features will cause this. 构建上的错误都指向新的自动属性功能,但我认为所有新功能都会导致此错误。

An example piece of code that causes a failure is using: 导致失败的示例代码正在使用:

public int MyFavouriteNumber { get; set; } = 7;

instead of 代替

private int _myFavouriteNumber = 7;
public int MyFavouriteNumber 
    { 
        get { return _myFavouriteNumber; } 
        set { _myFavouriteNumber = value; } 
    }

I've had a look around my build configuration, but I can't see anything that relates to C# 6 or Roslyn . 我已经查看了我的构建配置,但是看不到任何与C# 6Roslyn

What do I have to change to make my daily builds work again? 为了使我的日常构建再次正常工作,我需要更改什么?

Edit 编辑

Here's an example error (they're all the same, for auto properties). 这是一个示例错误(对于自动属性,它们都是相同的)。

Models\\Core\\Bookings\\BookingProduct.cs (29, 0) Invalid token '=' in class, struct, or interface member declaration Models \\ Core \\ Bookings \\ BookingProduct.cs(29,0)在类,结构或接口成员声明中无效的标记'='

Models\\Core\\Bookings\\BookingProduct.cs (29, 0) Invalid token '(' in class, struct, or interface member declaration Models \\ Core \\ Bookings \\ BookingProduct.cs(29,0)类,结构或接口成员声明中的无效标记'('

And here is the offending line: 这是违规行:

public virtual IList<BookingPricingAddon> AddonsPricing { get; set; } = new List<BookingPricingAddon>();

TheLethalCoder 's comments pointed me in the right direction. TheLethalCoder的评论为我指明了正确的方向。

The problem was that all of my projects were using Default as the target Language Version, which is fine if you're using VS 2015 , however, my .sln file had the following opening 3 lines: 问题是我所有的项目都使用Default作为目标语言版本,如果您使用的是VS 2015 ,这很好,但是,我的.sln文件具有以下三行:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0

Apparently, Visual Studio Online uses this to work out which version of MSBuild to use. 显然, Visual Studio Online使用它来确定要使用哪个版本的MSBuild (It was using 12 ). (它正在使用12 )。

Upgrading my solution to the following: 将我的解决方案升级到以下内容:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0

allowed Visual Studio Online to see that my IDE was using Roslyn, and therefore used MSBuild 14 . 允许Visual Studio Online看到我的IDE正在使用Roslyn,因此使用了MSBuild 14

The easiest way I found to upgrade is to click on the solution in Solution Explorer and then going to File > Save As > Solution File and overwrite your existing solution file, it just upgrades the first 3 lines. 我发现升级的最简单方法是在Solution Explorer单击解决Solution Explorer ,然后转到“ File > Save As > Solution File并覆盖您现有的解决方案文件,它只会升级前三行。

My builds are now successful. 我的构建现已成功。

I think the same could be achieved by setting the Language Version on each of your projects. 我认为可以通过在每个项目中设置Language Version来实现相同目的。 This can be done by going to your .csproj files and navigating to: 可以通过转到您的.csproj文件并导航至:

Properties > Build > Advanced > Language Version > C# 6.0

A good reference about the Default settings in each IDE can be found here . 此处可以找到有关每个IDE中Default设置的很好的参考。

每个IDE的默认编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM