'Errors in .NET 6 Hello World console application

After following the steps from Microsoft for setting up a new Console Application in .NET 6.0, I immediately get syntax errors from Intellisense. However, when I do dotnet run, the program runs as expected. weird

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Here's a screenshot of the folder, sample code and terminal

enter image description here

  • Program: Predefined type 'System.Object' is not defined or imported [HelloWorld]
  • Void: Predefined type 'System.Void' is not defined or imported [HelloWorld]
  • string: Predefined type 'System.String' is not defined or imported [HelloWorld]
  • Console: The name 'Console' does not exist in the current context [HelloWorld]

.NET SDKs installed

  • 5.0.201 [C:\Program Files\dotnet\sdk]
  • 6.0.102 [C:\Program Files\dotnet\sdk]

HelloWorld.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

Relevant VS Code Extensions:

  1. C# v1.24.0


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source