Duplicate 'Compile' items were included
Asked Answered
S

2

7

I have just added a SOAP webservice to a new Asp .net core project. When i try to build the project it results int he following error.

Microsoft.NET.Sdk.DefaultItems.targets(295, 5): [NETSDK1022] 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 https://aka.ms/sdkimplicititems. The duplicate items were: 'Service References/WebService/WebService.cs'

After a bit of Googleing i have seen similar errors when people rename files. But I haven't renamed anything this is a new project I have only added the web-service.

I checked the .csproj file and i get this

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <EnableDefaultContentItems>false</EnableDefaultContentItems>
    </PropertyGroup>

    <ItemGroup>
      <Reference Include="System.ServiceModel" />
    </ItemGroup>

    <ItemGroup>
      <WCFMetadata Include="Service References" />
    </ItemGroup>

    <ItemGroup>
      <WCFMetadataStorage Include="Service References\testing" />
      <WCFMetadataStorage Include="Service References\WebService" />
    </ItemGroup>

    <ItemGroup>
      <None Include="Service References\WebService\WebService.svcmap">
        <Generator>WCF Proxy Generator</Generator>
        <LastGenOutput>WebService.cs</LastGenOutput>
      </None>
      <None Include="Service References\WebService\WebService.webref" />
      <None Include="Service References\WebService\WebService.wsdl" />
    </ItemGroup>

    <ItemGroup>
      <Compile Include="Service References\WebService\WebService.cs">
        <AutoGen>True</AutoGen>
        <DesignTime>True</DesignTime>
        <DependentUpon>WebService.svcmap</DependentUpon>
      </Compile>
    </ItemGroup>


</Project>

I am only seeing one Compile so at a lost too understand whats being duplicated. I did try EnableDefaultCompileItems which has not resolved the issue. But considering what it does im not that happy with having it there, Even if it did work.

Any help in understanding the cause of this problem and fixing it would be appreciated.

Note: I am using Rider not Visual studio

Update

I did find this one link which seams to imply its an issue in rider and how it adds the web services Rider Creates Incorrect Webservice References for ASP .NET Core projects.

Im not sure that this is the same issue though. As i have created a .net core web api not asp .net core project.

Update 2

On the element in your project file, does it fix the issue if you change the "Include" to say "Update"?

The above was a suggestion from twitter. It appears to remove the original error but then results in a large number of name space errors.

WebService.cs(727, 82): [CS0234] The type or namespace name 'IClientChannel' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)

Sinecure answered 8/6, 2020 at 6:52 Comment(3)
Hi DalmTo. Have you tested this? – Narine
I may be wrong but i dont think .net core has a wwwroot folder at least not one that i can see. – Sinecure
«By design empty project template would not add wwwroot folder, controllers folders, models folder and so on.», in one comment here – Narine
S
1

Taking a key from the rider issue that this might be an issue with how rider is adding the web service.

I booted over to windows and started up visual studio. I was able to add the service with no issues.

I then took that project back to Linux and Rider.

I started to compere the two. The first difference I found was that Rider is not creating the connected services directory and all its contents. ConnectedService.json is kind of important 😊

enter image description here

The second was some major changes to the .csproj file

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>        
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />
        <PackageReference Include="System.ServiceModel.Http" Version="4.4.*" />
        <PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.*" />
        <PackageReference Include="System.ServiceModel.Security" Version="4.4.*" />
    </ItemGroup>

    <ItemGroup>
      <WCFMetadata Include="Service References" />
    </ItemGroup>   

</Project>

Basically you need to add the proper PackageReference's and remove a lot of the ItemGroup's which aren't needed. due to a change in how the .csproj files are validated.

Sinecure answered 8/6, 2020 at 8:48 Comment(2)
Yes, it seems to be a bug of Rider. You might see if others have reported to JetBrains, youtrack.jetbrains.com/issues/RIDER – Impetuous
You might want to check update number 1 in my question. :) Finding that report lead to the solution. – Sinecure
L
0

I found I was having this error on Google Cloud Run. I discovered I had made a namespace error with my controllers. On correcting error NETSDK1022: Duplicate 'Compile' items were included no longer occurred. The error was on .Net Core 5 Web.API. I was also using Rider which brought me here.

Leucopoiesis answered 12/2, 2021 at 2:57 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.