控制台应用程序:程序不包含适合入口点的静态 'Main' 方法 - 虽然 Main 存在
Console Application: Program does not contain a static 'Main' method suitable for an entry point - While Main exists
我的 .NET 5 项目的 Program.cs
看起来像这样:
使用系统;
namespace XmlGenerator.Cli
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(("Boo!!!"));
}
}
}
我的项目文件如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Master.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="Program.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Resource Include="Master.xml" />
</ItemGroup>
</Project>
当我尝试 运行 带有 F5
的应用程序时,出现以下错误:
CS5001 Program does not contain a static 'Main' method suitable for an entry point
我确实包含一个 Main
,所以可能有什么问题?
我的解决方案是从项目文件中删除所有 ItemGroup
元素,只留下:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>
我的 .NET 5 项目的 Program.cs
看起来像这样:
使用系统;
namespace XmlGenerator.Cli
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(("Boo!!!"));
}
}
}
我的项目文件如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Master.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="Program.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Resource Include="Master.xml" />
</ItemGroup>
</Project>
当我尝试 运行 带有 F5
的应用程序时,出现以下错误:
CS5001 Program does not contain a static 'Main' method suitable for an entry point
我确实包含一个 Main
,所以可能有什么问题?
我的解决方案是从项目文件中删除所有 ItemGroup
元素,只留下:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>