question

Micha1064-6571 avatar image
2 Votes"
Micha1064-6571 asked DanielZhang-MSFT action

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
5 |1600 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 AdamCaviness published

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.


· 1
5 |1600 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.

@TianyuSun-MSFT Thank you for including my related developercommunity issue into this discussion. I can tell you it is most defiantly not related to any VS extensions or VS settings. I have performed complete uninstall of VS on multiple occasions, (removing all on-disk caches, settings, and registry hive data). I have also tried complete uninstalls of our DevExpress SDK/components from my system and a complete uninstall of Management Studio (uses a VS shell) but that too was a dead end. I can tell you that running VS 2019 Preview does NOT demonstrate the problem. It's possible we all have other software on our system that is the root cause of an API call difference, etc. Attached is a complete list of my installed software via [NirSoft UninstallView]. It is an html file so please change the extension from txt to html before opening.

93559-report.txt





1 Vote 1 ·
report.txt (763.9 KiB)