Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish with async Main - Error CS8107: Feature 'async main' is not available in C# 7.0 #2751

Closed
tonysneed opened this issue Jan 9, 2018 · 17 comments

Comments

@tonysneed
Copy link

When I publish an ASP.NET Core Web API that has an async Main method: public static async Task Main, I get the following error:

Program.cs(13,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

This occurs even after setting the language version of each project in the solution to C# 7.2 for both Debug and Release build configurations.

Visual Studio 2017 Version: 15.5.2
OS Version: Windows 10 Pro Version 1709

@Eilon
Copy link
Member

Eilon commented Jan 9, 2018

@tonysneed can you show what your CSPROJ looks like? And also, after you publish your app, it's already been compiled, so where is the new compilation error coming from? A deployed app should just be DLL files, no CS files anymore.

@Tragetaschen
Copy link
Contributor

I had that happen to me recently on my Linux build machine. The reason was that I had only SDK 2.0 installed and the fix was adding 2.1 as well.

@tonysneed
Copy link
Author

Here is the csproj file for my ASPNETCORE Web Api:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PlexClaims.Abstractions\PlexClaims.Abstractions.csproj" />
    <ProjectReference Include="..\PlexClaims.ActiveDirectory\PlexClaims.ActiveDirectory.csproj" />
    <ProjectReference Include="..\PlexClaims.Data\PlexClaims.Data.csproj" />
    <ProjectReference Include="..\PlexClaims.Entities\PlexClaims.Entities.csproj" />
  </ItemGroup>

</Project>

Notice that LangVersion is latest (vs default), which is the value for all projects in the solution, both for Debug and Release.

Here is the Publish Profile I'm using:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>73d94c7c-d1a9-43f1-a12d-1e5abd08915d</ProjectGuid>
    <publishUrl>bin\Release\PublishOutput</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
</Project>

@Eilon
Copy link
Member

Eilon commented Jan 9, 2018

@tonysneed thanks for sharing those. Do you have more info about what is happening when the error shows up? Once the app is published, there's no Program.cs file to compile, so I'm at a loss as to how that is happening at all. At most there would be some CSHTML files being compiled (they get converted to CS files, then compiled with CSC.exe), but not the Program.cs file.

@tonysneed
Copy link
Author

@Eilon Yes, the error takes place when the Publish command is building the project. Because the build step of Publish fails, the web app is never published.

@Eilon
Copy link
Member

Eilon commented Jan 10, 2018

Oh I see, it's the publish process itself, not the published app.

@vijayrkn - any idea why the publish process would use different C# settings than a regular build?

@Eilon
Copy link
Member

Eilon commented Jan 10, 2018

@tonysneed I wonder if a different Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" is used in that case?

At least for debugging purposes, can you try moving the <LangVersion>latest</LangVersion> to the main <PropertyGroup> at the top? I always do that manually in my own CSPROJ files because I feel obligated to "refactor" my CSPROJ files 😄

@vijayrkn
Copy link

@Eilon - Don't know why this is happening. I will take a look.

@vijayrkn
Copy link

@tonysneed Did publish succeed after moving the LangVersion property to the main PropertyGroup?

@tonysneed
Copy link
Author

I'll try that. Need a bit of time.

@tonysneed
Copy link
Author

tonysneed commented Jan 10, 2018

@vijayrkn Moving LangVersion to the main property group fixed the issue for me. It looks like Publish ignores the Condition?

@vijayrkn
Copy link

Looks like an issue with the handling of the platform name in publish. As a work-around you can either move the property outside or add these additional conditions.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU' or '$(Configuration)|$(Platform)'=='Debug|Any CPU'">
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' or '$(Configuration)|$(Platform)'=='Release|Any CPU'">
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

@Eilon
Copy link
Member

Eilon commented Jan 10, 2018

@vijayrkn should this bug go to https://github.com/aspnet/websdk ?

@vijayrkn
Copy link

This is a bug in the VS side. VS bugs are tracked in developer community.

Found another bug in the developer community for the same issue.
https://developercommunity.visualstudio.com/content/problem/160971/migrating-from-vs2017-1545-to-1550-causes-cs8107-e.html

This bug can be closed as dupe and we can use the developer community bug to track the issue progress.

@Eilon
Copy link
Member

Eilon commented Jan 10, 2018

Thanks @vijayrkn !

@llonikko
Copy link

I got the same error during build time. I used the .NET Core CLI.

Adding the LangVersion to the main PropertyGroup fixed the issue for me.

@MHanafy
Copy link

MHanafy commented May 23, 2019

I got the same error building via Azure DevOps; When I checked the project file, it didn't have the LangVersion property at all, although VS Designer show that the default(latest) is selected.

Issue got resolved after manually setting the value to Latest.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants