Build/Test Issues

NCrunch Build failure on C# 6 projects

Started by fcournoyer on 8,976 views

Hi!

Recently moved back to a project, with ongoing development from my team, and am now with a new computer.
So I downloaded the latest version of NCrunch (3.6)
And I pulled the newest code from git, involving quite some changes.

In Visual Studio, everything compiles and runs successfully.
However NCrunch gives compile error about the language version
: Feature 'nameof operator' is not available in C# 5. Please use language version 6 or greater.


Looking in details, the Project's Language Version was "Default".
Changed it to 6.0, still same problem. Could not find any NCrunch configuration about that.
Tried older version of NCrunch (3.2.0.3), same problem.

Windows 10 Pro, 64 bit
Visual Studio 2015 Pro
Projects are .NET 4.5.1

Some other projects that are using C# 6 features are compiled correctly with NCrunch. I can't see for now the difference why.

Any clues?
Francois


Hi Francois,

Thanks for sharing this problem.

I've had a couple of other users report similar problems. Unfortunately I can't tell why this is happening. Is there any chance you can share a sample project that reproduces this issue?
Hi Remco!
Thanks for the quick response.
Sadly this contains sensitive code from the company I'm working for, that I can't share.

Obviously, making a small project using "nameof" operator does get compiled correctly by NCrunch.

If I find anything which fixes it, I'll let you know.

Francois
fcournoyer wrote:Hi Remco!
Thanks for the quick response.
Sadly this contains sensitive code from the company I'm working for, that I can't share.


Understood. This is usually the case :(

fcournoyer wrote:
Obviously, making a small project using "nameof" operator does get compiled correctly by NCrunch.

If I find anything which fixes it, I'll let you know.


Thanks!
Hi Remco!

I finally found the problem, which is simply because of the "Default Platform" in the csproj.
It usually happened on older projects, which might have extra platforms existing (normally unused).

For example, a project "Foo" is always compiled using x86 (by the Configuration Manager in Visual Studio), and uses Language Version to 6 (or default).
However the AnyCPU platform also exists on that project, and it uses C#5, by having <LangVersion>5</LangVersion> in the PropertyGroup node.

Then, the default platform in the csproj is using the AnyCPU (thus the one used by NCrunch)
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

I found it by searching for <LangVersion>5</LangVersion> in all my csproj, and found those leftover platforms. A simple cleanup and then everything compiles!

So it's pretty much a user-side problem, and I don't know how you could detect it.

Francois
Hi Francois,

Great find! I'm also not sure how I would detect this. But at least now I know that it's possible, which means I can advise other people when they report the problem to me. You'd be surprised at how common this is. I guess there might be something in the VS tooling that makes it happen unintentionally.
Well for us there's history reasons on why it happened.

First, at some point, we had a slow transition from VS 2013 to VS2015. In order that it compiles for everyone, we have set C#5 to all projects, so that people coding in 2015 don't break the build by using C#6 features not compatible for those on VS2013.

Also, normally when creating a project, it is initialized with AnyCPU. For most software, we after this change it to x86 specifically. We forgot to remove the AnyCPU target on some of them. And in that case, we do not change the "Default Platform" that NCrunch uses (defaults to AnyCPU).
So that means that those project got "C#5" to both AnyCPU and x86 platform.

Then, when deciding that everyone should use VS2015 and C#6, we manually changed most projects using Visual Studio "Project Properties". Some older project also had to keep their C#5 so we didn't do a mass-replace.
So you can see how only the project platforms compiled in Visual Studio got converted.

I'm the only one in the team using NCrunch, so when pulling "master", I started getting those error only with NCrunch.

Francois
I just wanted to post the solution to this problem in the projects I currently work on.

It was an old version of StyleCop.MSBuild causing build errors. It seems that it is fixed from version 4.7.51 (Beta).
See here: https://stackoverflow.com/questions/35113492/is-stylecop-4-7-compatible-with-c-sharp-6-0-code

After updating StyleCop.MSBuild to version 5.0.0, NCrunch runs smoothly.

Post a reply

Log in to reply.