What caused an unexpected build error in C# with Visual Studio


I have a C# program, and I am using Microsoft Visual Studio. I have been able to build and run the program without any issue for a long time. Now, unexpectedly I get this error:

I:\source\megaSearch\tempCodeRunnerFile.cs(1,9): error CS1001:
Identifier expected [i:\source\megaSearch\megaSearch.csproj]
I:\source\megaSearch\tempCodeRunnerFile.cs(1,9): error CS1002: ;
expected [i:\source\megaSearch\megaSearch.csproj]

So, it is in the project file but I have not edited the project file or opened it.

Here is the project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

CS1001 is “Identifier expected” but I do not see how there is any missing bit of code in the line <Project Sdk="Microsoft.NET.Sdk">.

So, I asked I have found the solution which I will post next and leave this post here for a next person.

Leave a Reply

Your email address will not be published. Required fields are marked *