Visual Studio Enterprise 2017 v15.3.2
.NET framework 4.7.02046
VSTS Build Agent: 2.120.2 (running on Server 2008, latest patches)
Steps to Reproduce:
void Main()
to async Task Main()
Expected Behavior:
Build completes and recognises async Task Main
as valid C# 7.1
Actual Behavior:
Build fails with error:
2017-08-29T08:49:18.0026052Z ##[error]Program.cs(11,22): Error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater.
Adding Roslyn compilers package does not fix this. Same error.
Notes:
First attempt on build server as 4.7 failed as the SDK was not installed (odd, since I'd installed VS 2017 on the machine earlier). Downloaded and ran NDP47-DevPack-KB3186612-ENU.exe
on the build server to fix this.
Second build failed as expected (log below):
2017-08-29T08:48:44.2515948Z CoreCompile:
2017-08-29T08:48:44.2672205Z E:\Microsoft Visual Studio 2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:anycpu32bitpreferred /errorreport:prompt /warn:4 /define:TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Net.Http.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\CSharp7_1_Test.exe /ruleset:"E:\Microsoft Visual Studio 2017\Enterprise\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "D:\BuildAgent1\_work\_temp\.NETFramework,Version=v4.7.AssemblyAttributes.cs"
2017-08-29T08:48:45.2516396Z Using shared compilation with compiler from directory: E:\Microsoft Visual Studio 2017\Enterprise\MSBuild\15.0\Bin\Roslyn
2017-08-29T08:49:18.0026052Z ##[error]Program.cs(11,22): Error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater.
2017-08-29T08:49:18.0026052Z Program.cs(11,22): error CS8107: Feature 'async main' is not available in C# 7. Please use language version 7.1 or greater. [D:\BuildAgent1\_work\89\s\CSharp7_1_Test.csproj]
2017-08-29T08:49:18.0807322Z ##[error]CSC(0,0): Error CS5001: Program does not contain a static 'Main' method suitable for an entry point
2017-08-29T08:49:18.0807322Z CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [D:\BuildAgent1\_work\89\s\CSharp7_1_Test.csproj]
2017-08-29T08:49:18.1588592Z Done Building Project "D:\BuildAgent1\_work\89\s\CSharp7_1_Test.csproj" (default targets) -- FAILED.
[edit] I also tested by using the "Hosted VS2017" build agent queue - this failed with the same error.
Thanks to @jcouv for taking a look at this.
I noticed there is a GitHub project for agents at https://github.com/Microsoft/vsts-agent/issues - not sure if we should cross-post the issue there, or leave it here?
Leave it here for now. I'm reached out to get contacts. I'll move the issue if needed.
Thanks
OK thanks
@conficient, VSTS team confirmed that all of the public hosted machines have been updated with VS 15.3 and .NET Core 2.0.
This prompted me to read your repro in more details and it looks like the C# 7.1 compiler is indeed used, but it is using LangVersion 7.0.
If you project file is properly set with LangVersion 7.1, I do not yet know why the build would use 7.0. Can you double-check your project file?
One more way to troubleshoot this issue is to include a #error version
pragma in your code (details) and submit it for build. The error you get back will confirm what LangVersion was passed to the compiler.
I just checked and <LangVersion>7.1</LangVersion>
was in the project file.
But as I did so I notice ( _fx: forehead hitting desk_ ) it was in the debug
property group. So it compiled okay locally (debug) but the build definition was release. Confirmed by adding the C# 7.1 to any CPU and release property groups and it compiles fine on Build Agent.
Sorry for the oversight!
I did this too, the easiest way to do it for all project configurations:
Right-click YourProject
, click Properties
Click Build
if it's not already selected
Change Configuration
to All Configurations
Click Advanced...
Change the language version
Also confirmed this behavior in Visual Studio for Mac (version 7.2.2 (build 11). To fix it in this IDE:
YourProject
, click Options
Build > General
Language Options > C# Language Version
to Version 7.1Why on earth is language version a build configuration-specific setting, anyway? For 99.9999 (few more nines)% of the cases you are compiling the same code for the different configurations, so why would we ever want different language features?
Pretty silly mistaken to be able to get caught on.
@bojingo There is an issue tracking this (LangVersion injected into project file by UI or API should not be configuration-specific): https://github.com/dotnet/project-system/issues/2732
I do not know why it was that way in the first place.
In fact there is a real architecture bug which is not fixed:
Build on the command line configuration Release => works fine
Build on the command line configuration Staging => fails
Because the "Staging" configuration does not exist in project A, msbuild fails.
Either "C# latest" should be the default, or msbuild should know how to handle this situation better.
"C# latest" being the default can be problematic because as soon as a new version of C# comes out doesn't mean all your build agents and such are immediately updated accordingly. The intent of the setting is to prevent people from using new features before they are ready for it. It just should be at the project level instead of specific build configuration level. (think of the settings in the project property pages that can't be changed independently based on build configuration).
Then again...at least it would be a more predictable and intuitive error, so maybe that would be much preferred! 馃憤 @softlion
My problem was that, when I changed lang level via interface, it just update the debug build configuration in csproj, not the release.
Wow, been struggling with this. My build server wasn't picking up 7.2 and I didn't realize I needed it for the release configuration. Thanks!
The interface should update both configurations, the error is not clear and takes time to find out what's happening in the first time.
@paulohenriquesi Thanks, i made the same mistake, now i will use the 芦 All Configuration聽禄 for thing like that.
How to fix this in DOTNETCore Project? I mean change the LangVersion
@vnextcoder Here's some information on setting the LangVersion
in your project(s).
This does not work if you just want to set it to latest. The solution is to provide the msbuild argument as shown here: https://stackoverflow.com/questions/48050676/how-do-i-set-csc-langversion-when-building-in-vsts
Yes and that does not work. Mine was already set similar to that.
Still a problem with VS2017 15.9.24, which is suppose to support C#7.2 and it doesn't by "default"
Some team members are using VS2019 which by "default" for language settings has NO XML verbose specifications for the solution, nor any projects in that solution. This is also true in VS2017.
If while using VS2019, and you have a public/private protected class defined... and you open this in VS2017, you get the
"...is not available in C# 7. Please use language version 7.2 or greater", which is should if every project has "default" enabled.
this works fine in VS2019, but not VS2017.
you cannot simply configure the "All Configurations > Advanced..." property for the language in VS2019, it simply will not allow you to do so. And in VS2017, you have to configure it specificaly for C#7.2, at EACH project level. It does not work at the solution level using Directory.Build.props (as stated here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version ) to do it as a 'global' solution language specification.... you still MUST do this at each individual project level.
so... the "default" in VS2017 is C#7.0 and nothing greater.... to share the same code between VS2017 and VS2019, you either need to stick with C#7.0 convention (by not using the secured private protected method and just protected) or manual slap all that verbose XML into every single project. very irritating.
Most helpful comment
I just checked and
<LangVersion>7.1</LangVersion>
was in the project file.But as I did so I notice ( _fx: forehead hitting desk_ ) it was in the
debug
property group. So it compiled okay locally (debug) but the build definition was release. Confirmed by adding the C# 7.1 to any CPU and release property groups and it compiles fine on Build Agent.Sorry for the oversight!