Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate 'Compile' items were included

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?)

like image 597
DaImTo Avatar asked Jun 08 '20 06:06

DaImTo


1 Answers

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.

like image 59
DaImTo Avatar answered Oct 19 '22 02:10

DaImTo