Error MSB3105: The item [*.cs] was specified more than once in the "Sources" parameter.
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
I have built a NuGet package containing a single cs content file (see below; should be renamed). When I create a new Windows Forms App (.NET Framework) using Visual C#, use PackageReference as my NuGet package management format and add the package, I get the error "The item "C:\Users\jgrus\.nuget\packages\FooBar\1.0.0\contentFiles\cs\any\FooBar.cs" was specified more than once in the "Sources" parameter. Duplicate items are not supported by the 'Sources' parameter" when compiling. The content file is correctly identified as a resource that should be compiled into the application. Also, IntelliType identifies the content of this file.
In my digging it appears as though the problem may relate to the reference to the code file in project.assets.json as well as *.csproj.nuget.g.props. Both items instruct MSBuild to compile the resource. If I manually adjust the properties in project.assets.json to not compile the resource, it builds successfully and functions as desired.
To reproduce:
- Create a new Windows Forms App using C# in Visual Studio 2017
- Make sure NuGet preferences are to use PackageReference (Tools -> Options -> NuGet Package Manager -> General -> Default package management format: PackageReference
- Add the NuGet package below
- Compile
[FooBar.1.0.0.nupkg.zip](https://github.com/Microsoft/msbuild/files/876477/FooBar.1.0.0.nupkg.zip)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.