sdk: error MSB3105: The item "XXX.cs" was specified more than once in the "Sources" parameter.

While trying to build this PR https://github.com/Microsoft/Docker.DotNet/pull/144 for some reason it is thinking I have a duplicated file in the CI build at AppVeyor.

C:\Program Files\dotnet\sdk\1.0.0-preview5-004460\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB3105: The item "AnonymousCredentials.cs" was specified more than once in the "Sources" parameter.  Duplicate items are not supported by the "Sources" parameter. [C:\projects\docker-dotnet\Docker.DotNet\Docker.DotNet.csproj]

1.0.0-preview5-004232 build it just fine. However, the latest version 1.0.0-preview5-004460 throw this error for the same project…

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

In my case this was a problem as the .csproj.user file had a reference in it as well as the .csproj - so have a look in both files - if it exists in both this can cause the problem

The latest SDK adds all .cs files by default now without any “Compile” lines.

To fix the error either:

  1. Remove all “Compile” elements from your .csproj and let the SDK add all .cs files to your project automatically. See https://github.com/dotnet/sdk/blob/master/src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpConsoleApplication/ProjectTemplate.csproj for the latest .csproj console app template. Or https://github.com/dotnet/sdk/blob/master/src/Templates/ProjectTemplates/CSharp/.NETCore/CSharpClassLibrary/ProjectTemplate.csproj for the latest class library template for examples.
  2. If you want to control which files are added and don’t want the SDK to automatically added them, set <EnableDefaultItems>false</EnableDefaultItems> property in your .csproj.

This experience will get better once #600 is fixed.