11

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

Yea i reverted back to this in the meantime as i can't find the source of the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.