I had upgraded the solution/projects to VS 2019 & .NET Core in all projects to netcoreapp3.1 & netstandard1.2 . When compiled WebApp csproj is still showing older version because of this compiler error message "Program does not contain a static Main
method suitable for an entry point". I'm using async which is now permitted in C# version 8 & up. I even try LangVersion as latest or preview w/ no luck, I read documentation that we don't need to specify LangVersion starting with .NET Core 3.0 & up as it
will be done automatically. So what could be the problem here?
Yes but it is likely done when creating a new project and here it seems an upgrade in which case it is likely left unchanged. Also you have : <LangVersion>preview</LangVersion>
Yes but it is likely done when creating a new project and here it seems an upgrade in which case it is likely left unchanged. Also you have : <LangVersion>preview</LangVersion>
Edit: ah you changed to preview and tried a 8.0 earlier ???
I did create a new Web Project & updated the Main to use async. It still fail, even though this is a clean seperation from everything else. I even try 8.0 & latest as you suggested, still same error.
The latest C# compiler determines a default language version based on your project's target framework or frameworks. Visual Studio doesn't provide a UI to change the value, but you can change it by editing the csproj file.
Member
2 Points
12 Posts
csproj is not using latest C# version in VS 2019
May 07, 2020 12:40 PM|fletchsod2|LINK
I had upgraded the solution/projects to VS 2019 & .NET Core in all projects to netcoreapp3.1 & netstandard1.2 . When compiled WebApp csproj is still showing older version because of this compiler error message "Program does not contain a static Main method suitable for an entry point". I'm using async which is now permitted in C# version 8 & up. I even try LangVersion as latest or preview w/ no luck, I read documentation that we don't need to specify LangVersion starting with .NET Core 3.0 & up as it will be done automatically. So what could be the problem here?
[ Program.cs ]
public class Program
{
public async static void Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => {
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webBuilder.UseKestrel();
webBuilder.UseAzureAppServices();
webBuilder.UseStartup<Startup>();
//webBuilder.UseSerilog()
})
.ConfigureLogging((logging) =>
{
//logging.AddSerilog();
})
.Build()
.RunAsync();
}
}
[ csproj ]
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<VersionPrefix>1.2.0</VersionPrefix>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>ABCoA.Payments.CustomerWeb</AssemblyName>
<PackageId>ABCoA.Payments.CustomerWeb</PackageId>
</PropertyGroup>
<PropertyGroup>
<LangVersion>preview</LangVersion>
</PropertyGroup>
</Project>
All-Star
48740 Points
18193 Posts
Re: csproj is not using latest C# version in VS 2019
May 07, 2020 01:05 PM|PatriceSc|LINK
Hi,
Yes but it is likely done when creating a new project and here it seems an upgrade in which case it is likely left unchanged. Also you have : <LangVersion>preview</LangVersion>
Try to use whatever you prefer from https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#c-language-version-reference
Edit: ah you changed to preview and tried a 8.0 earlier ???
All-Star
53751 Points
24069 Posts
Re: csproj is not using latest C# version in VS 2019
May 07, 2020 01:07 PM|mgebhard|LINK
I can't think of a good reason for a Web Application's entry point to be async. Can you explain the problem you are trying to solve?
Member
2 Points
12 Posts
Re: csproj is not using latest C# version in VS 2019
May 07, 2020 01:08 PM|fletchsod2|LINK
I did create a new Web Project & updated the Main to use async. It still fail, even though this is a clean seperation from everything else. I even try 8.0 & latest as you suggested, still same error.
Member
2 Points
12 Posts
Re: csproj is not using latest C# version in VS 2019
May 07, 2020 01:11 PM|fletchsod2|LINK
Here's the example of why, see "RunAsync()" below. Startting with C# 7.1 & up, the Main can be async now. We been moving things over to async as well.
public class Program
{
public async static void Main(string[] args)
{
await CreateHostBuilder(args).Build().RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
P.S. Why is .NET forum keep adding <div></div> tags here? How to make it not do that?
All-Star
53751 Points
24069 Posts
Re: csproj is not using latest C# version in VS 2019
May 07, 2020 01:28 PM|mgebhard|LINK
I added async to the main method in a new Core 3.1 project without issue.
The latest C# compiler determines a default language version based on your project's target framework or frameworks. Visual Studio doesn't provide a UI to change the value, but you can change it by editing the csproj file.
I still don't get the benefit of doing this.