Reputation: 1373
I have a console application which has async calls for e.g. the signature of the main method looks like this
static async Task MainAsync(string[] args)
{
}
I am able to compile the build in my local machine. But I have a VSTS (DevOps Azure) CI/CD pipeline where I am using a custom hosted agent in that machine, over there once the CI executes it gives the error:
##[error]CSC(0,0): Error CS5001: Program does not contain a static 'Main' method suitable for an entry point
Upvotes: 7
Views: 5421
Reputation: 840
https://www.visualstudiogeeks.com/azure/devops/using-latest-version-of-csharp-with-dotnetcore
in pipeline in visual studio build add to MSBuild Arguments
/property:langversion=latest
or
Edit the c# Project and add
<LangVersion>latest</LangVersion>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PackageAction>BuildDefault</PackageAction>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PackageAction>BuildDefault</PackageAction>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Upvotes: 3
Reputation: 83
I got it working by forcing the user agent to use VS2017. Click phase 1 and then change it to the following: HostedVS2017
This forces the user agent to use 2017 which has the latest version of C# instead of 2015 (which it was falling back to for me).
Upvotes: 5
Reputation: 1921
Can you try building your local code in release mode and see if you are getting the same issue.
Make sure to add C# 7.1 to any CPU and release property groups.
Right-click Your Project, click Properties
Click Build if it's not already selected
Change Configuration to All Configurations
Click Advanced...
Change the language version
Refer this issue in github for more details.
https://github.com/dotnet/roslyn/issues/21783
Upvotes: 3