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?
To publish from Visual Studio, do the following: Change the solution configuration from Debug to Release on the toolbar to build a Release (rather than a Debug) version of your app. Right-click on the project (not the solution) in Solution Explorer and select Publish. In the Publish tab, select Publish.
Create an ASP.NET Core applicationOpen that empty directory in VS Code by selecting File -> Open Folder. Open the terminal by using the shortcut Ctrl + Shift + ` or Terminal -> New Terminal. Then, it will show you the list of ASP.NET project templates. Select the web application option.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With