Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 publish ASP.NET Core app with C# 7.2

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?

like image 390
adrian h. Avatar asked Dec 29 '17 14:12

adrian h.


People also ask

How do I Publish a program in Visual Studio 2017?

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.

How do I create a .NET Core application code in Visual Studio?

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.


1 Answers

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.

like image 106
user1336 Avatar answered Oct 16 '22 10:10

user1336