question

Micha1064-6571 avatar image
0 Votes"
Micha1064-6571 asked ·

NETSDK1022

Hello! Every time I create a new Net Core console project ("Hello world") and add a new class, I get the NETSDK1022 error ("duplicated compile items"). I have already reinstalled Visual Studio 2019, probably deleted all possible files and imported the configuration from a properly functioning VS installation on another computer. In this case, nothing helps. When I add a new class then Visual Studio adds a section to the project file:
<ItemGroup>
<Compile Include = "Class1.cs" />
</ItemGroup>
which causes the error. If I delete it, the project will compile correctly. But I have to do this after adding each new class. In other VS installations, this section is not added. Why in this case VS adds this section? What settings can cause this? Thank you in advance for your answer.

dotnet-csharpvs-msbuild
· 5
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,

See the following description and solution on this page.


0 Votes 0 ·

Thank you, but this is not a solution to my problem. if I add <EnableDefaultCompileItems> to my project, it changes only the error message to "CS5001 Program does not contain a static 'Main' method suitable for an entry point.", and adding a new class still causes that it is added to the Compile items section in the project file.

0 Votes 0 ·

Please download and build the following console project, see if it will run for you.

Project file

 <Project Sdk="Microsoft.NET.Sdk">
    
   <PropertyGroup>
     <OutputType>Exe</OutputType>
       <LangVersion>9.0</LangVersion>
       <TargetFramework>net5.0</TargetFramework>
   </PropertyGroup>
    
 </Project>

There is one class file besides Program.cs


0 Votes 0 ·
Show more comments

1 Answer

TianyuSun-MSFT avatar image
0 Votes"
TianyuSun-MSFT answered ·

Hello @Micha1064-6571 ,

Thank you for taking time to post this issue in Microsoft Q&A forum.

I tested on my side, but I failed to reproduce your issue(Visual Studio 2019 Community). The .NET Core Console project worked well. I think this is an issue which is related to environment, extensions or VS IDE(under certain conditions).

There is a similar thread: Prevent VS from adding explicit compile tags to csproj and this issue has been reported in our Developer Community, please check this thread: Compile elements added to project file when EnableDefaultCompileItems was not set to false, and vote, add comments then follow that thread, if this is a potential issue, Visual Studio Product Team will help to fix it.

Feel free to contact us if you have any concern.

Best Regards,
Tianyu


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.