title: Fixing the "Duplicate 'Compile' items were included." error in Visual Studio
body: <p>This is a very annoying VS error, I'm on VS 2019 16.8.1</p>
  <p>I spend a lot of time fixing it:</p>
  <blockquote>
  <p>Duplicate 'Compile' items were included. The .NET SDK includes
  'Compile' items from your project directory by default. You can either
  remove these items from your project file, or set the
  'EnableDefaultCompileItems' property to 'false' if you want to
  explicitly include them in your project file. For more information,
  see <a href="https://aka.ms/sdkimplicititems" rel="nofollow noreferrer">https://aka.ms/sdkimplicititems</a>. The duplicate items were:
  'Program.cs'  Service.Host
  Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets    295</p>
  </blockquote>
  <p>I can't understand what causes this error.
  I commented out the <code>Include</code> tags in the *.csproj files, but the problem is that I have more than 30 projects, all of a sudden they all have the same duplicate error, going through all of them to fix such a mysterious error seems unsafe action, some of these projects are legacy projects that haven't been touched for a long time.
  Another problem in the solution commenting the <code>Include</code> tags is that I have some project with this include structure:</p>
  <pre><code>  &lt;ItemGroup&gt;
      &lt;Compile Include=&quot;Contracts.cs&quot; /&gt;
      &lt;Compile Include=&quot;IKey.cs&quot;&gt;
        &lt;DependentUpon&gt;Contracts.cs&lt;/DependentUpon&gt;
      &lt;/Compile&gt;
      &lt;Compile Include=&quot;ISigner.cs&quot;&gt;
        &lt;DependentUpon&gt;Contracts.cs&lt;/DependentUpon&gt;
      &lt;/Compile&gt;
    &lt;/ItemGroup&gt;
  </code></pre>
  <p>commenting this will affect the project structure.</p>
  <p>I tried to comment out the <code>CheckForDuplicateItems</code> tags in the file:</p>
  <p>&quot;C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets&quot;,</p>
  <p>and the errors are gone.</p>
  <p>EDIT</p>
  <p>I just noticed that the .NET 5 version (..\sdk\5.0.101..) is included in the targets file path, I only have one project with .NET 5, does this cause the problem?</p>