I've switched over to using the RC version Visual Studio 2015 for most of my OSS coding recently, and I've really fallen in love with some of the new C# 6 features. Especially the
nameof operator, expression-bodied members and getter-only properties.
To convert my code to C# 6, I've been using ReSharper's solution-wide quick-fixes to convert to getter-only properties etc.:
It's really nice! Once everything was converted, I pushed the code to GitHub, the AppVeyor CI kicked in, and everything broke! Ouch.
Here's the kind of errors that showed up in my build log:
error CS1519: Invalid token '??' in class, struct, or interface member declaration
It was obvious that it was the C# 6 syntax that was confusing MSBuild, but it wasn't immediately obvious how I could tell AppVeyor to use a newer version that supported C# 6.
I did a quick search and found this (somewhat) helpful AppVeyor blog post that had instructions on how to switch to a Visual Studio 2015 CTP image.
You basically have to do two things under the Environment tab (this is updated to use VS 2015 RTM):
- Switch Operating system to Visual Studio 2015.
- Make sure that MSBuild 14.0 is on your PATH by adding
set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%to Install script.
This can also be done by adding the following lines to your
os: Visual Studio 2015 install: - set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
UPDATE (23.07.2015): Visual Studio 2015 has now RTM'ed and AppVeyor has updated its images. This means that you should now use the
Visual Studio 2015 image instead of
Visual Studio 2015 RC.
Great! That should work, right? Nope. Not for me (or this guy) at least. The build logs still show
Microsoft (R) Build Engine version 12.0.31101.0, so it's clearly not using the right MSBuild version.
The problem is that even though you have MSBuild 14.0 installed (with the image) and it is on your PATH, it won't automatically be used unless the solution file indicates it, and since this is an older solution, created with VS 2013, it won't.
Even though it took me some time to figure out, it turns out the solution to the problem is really easy. Just pop open the sln file and replace the line
VisualStudioVersion = 12.0.31101.0
VisualStudioVersion you already have in there with
VisualStudioVersion = 14.0.22823.1
This should make AppVeyor use MSBuild 14.0 (you'll see
Microsoft (R) Build Engine version 14.0.22823.1 in the logs) instead of 12.0 and successfully build your C# 6 code!
I'd love to hear if you have a better or alternative solution to this. Leave a comment below.
I hope anyone finds this helpful :)