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 Referencestesting" />
<WCFMetadataStorage Include="Service ReferencesWebService" />
</ItemGroup>
<ItemGroup>
<None Include="Service ReferencesWebServiceWebService.svcmap">
<Generator>WCF Proxy Generator</Generator>
<LastGenOutput>WebService.cs</LastGenOutput>
</None>
<None Include="Service ReferencesWebServiceWebService.webref" />
<None Include="Service ReferencesWebServiceWebService.wsdl" />
</ItemGroup>
<ItemGroup>
<Compile Include="Service ReferencesWebServiceWebService.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?)
2
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 😊The second was some major changes to the .csproj file
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.
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.