001*_*001 51 c# console console-application visual-studio-2017 .net-core-2.0
无法执行以下代码错误CS5001程序不包含适用于入口点的静态"主"方法
这个错误信息是什么意思?
class Program
{
static async Task MainAsync(string[] args)
{
Account.accountTest accountTest = new Account.accountTest();
bool result = await accountTest.CreateAccountAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
Jon*_*eet 154
这意味着您目前没有适合您的应用程序的入口点.
该代码几乎可以与C#7.1一起使用,但您需要在项目文件中明确启用C#7.1:
<LangVersion>7.1</LangVersion>
Run Code Online (Sandbox Code Playgroud)
或更一般地说:
<LangVersion>latest</LangVersion>
Run Code Online (Sandbox Code Playgroud)
您还需要重命名MainAsync
为Main
.例如:
Program.cs中:
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
await Task.Delay(1000);
}
}
Run Code Online (Sandbox Code Playgroud)
ConsoleApp.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
...构建并运行良好.