dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Error MSB3105: The item [*.cs] was specified more than once in the "Sources" parameter. #1921

Open jgrusling opened 7 years ago

jgrusling commented 7 years ago

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:

FooBar.1.0.0.nupkg.zip

havi01 commented 7 years ago

I am having this problem as well.