Reputation: 3026
I have a Asp.Net MVC Core website that's using public static async Task Main()
. For that to work I've set the language version to C# 7.2 (in the properties -> build -> advanced dialog, double checked in the csproj) for both Debug and Release build configurations.
App builds and starts fine in both Debug and Release mode.
Now, I'm trying to publish it to an Azure Website directly from Visual Studio 2017 15.5.2 (with WebDeploy) and I get this:
Program.cs(17,29): Error CS8107: Feature 'async main' is not available in C# 7.0. Please use language version 7.1 or greater. CSC(0,0): Error CS5001: Program does not contain a static 'Main' method suitable for an entry point
In the output window I see it's running C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe
with some flags, probably one of them is wrong?
Anyone know if this is a known issue or I'm doing something wrong?
Upvotes: 11
Views: 655
Reputation: 7215
This appears to be a bug in Visual Studio. Adding this line to main property group in the .csproj file resolved the issue for me:
<LangVersion>latest</LangVersion>
The issue was also reported here in the ASP.NET Home repository.
Upvotes: 3
Reputation: 239460
Not an answer, per se, but for what it's worth async Main
is just syntactic sugar. Behind the scenes Roslyn just adds the standard void Main
wrapper construction:
static void Main(object[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(object[] args)
{
// your code
}
It's probably not worth your time trying to get the server on the same page C# version-wise, just to save literally three lines of code.
Upvotes: 2