error in csproj - duplicate item
Asked Answered
G

16

62

I have error from visual studio 2010:

Error 1 The item "CrossDomainService.svc.cs" was specified more than once in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter. WcfServiceDomain

and from msbuild

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(160,9) : error MSB3105: The item "CrossDomainService.svc.cs" was specified more than o nce in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter. [C:\inetpub\Wwwroot\axaptaWcfConnection\WcfServiceDomain\WcfSer viceDomain.csproj]

My file is csproj:

    <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{8D40933A-E036-4CD0-9003-314A692724D5}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>WcfServiceDomain</RootNamespace>
    <AssemblyName>WcfServiceDomain</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile />
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <UpgradeBackupLocation>
    </UpgradeBackupLocation>
    <OldToolsVersion>4.0</OldToolsVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System.Web.ApplicationServices" />
    <Reference Include="System.Web.DynamicData" />
    <Reference Include="System.Web.Entity" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.EnterpriseServices" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.ServiceModel.Web" />
    <Reference Include="System.Web.Services" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="ClientAccessPolicy.xml" />
    <Content Include="CrossDomainService.svc" />
    <Content Include="Service1.svc" />
    <Content Include="Web.config">
      <SubType>Designer</SubType>
    </Content>
    <Content Include="Web.Debug.config">
      <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="Web.Release.config">
      <DependentUpon>Web.config</DependentUpon>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="CrossDomainService.svc.cs">
      <DependentUpon>CrossDomainService.svc</DependentUpon>
    </Compile>
    <Compile Include="ICrossDomainService.cs" />
    <Compile Include="Service1.svc.cs">
      <DependentUpon>Service1.svc</DependentUpon>
    </Compile>
    <Compile Include="IService1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>51421</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>
          </IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
</Project>

I not see any duplicate :/ Any idea from this error ??

Gourami answered 27/12, 2010 at 15:34 Comment(0)
G
-2

Only solution was recreate project :/

Gourami answered 21/1, 2011 at 11:39 Comment(3)
I agree. It will really suck if you have a very huge project and you need to recreate your the entire solution! :'(Teirtza
I agree with You, it's realy weak solution. i hope that Jindra solution could help...Gourami
Not a practical solutionOrmazd
M
110

I was facing the same problem in my solution with the same error for one of the source file,

I fixed it out as follows,

  1. Check for the file name for which the error is given.

  2. Find out in which project the file is included.

  3. Open the .csproj file for that particular project (This file can be found in the directory where solution is placed).

  4. Search for the file name for which the error is thrown in the .csproj file.

  5. You will find two entries of the line such as

 <Compile Include="duplicate.aspx.cs">
      <SubType>ASPXCodeBehind</SubType>
      <DependentUpon>Duplicate.aspx</DependentUpon>
    </Compile>


 <Compile Include="duplicate.aspx.cs">
      <SubType>ASPXCodeBehind</SubType>
      <DependentUpon>Duplicate.aspx</DependentUpon>
    </Compile>
  1. Delete any one line from one of them.

  2. Save the changes.

  3. Reload the project your error must have gone.

Marybelle answered 28/6, 2013 at 9:42 Comment(2)
In my case NetStarter's trick worked for me. I would like to mark it as an answer for sure. You can see detailed thread Here linkPivoting
There is no dark magic here. The other answers are WAY wrong. This is the only proper way to handle this issue.Maldonado
B
4

You could just open the solution in a regular text editor and remove the dups by hand

Baize answered 16/9, 2011 at 15:1 Comment(0)
J
4

For those who encountered the same problem, nothing helped them and they do not want to recreate the project: Try to delete YourPojectName.csproj.user file. It helped me. I modified the .csproj manually before and the modification introduced (somehow) probably some discrepancy to the two files.

Jarrell answered 10/6, 2013 at 6:18 Comment(1)
I couldn't find a file that is referenced twice and removing the user file did the job, thanks!Broker
O
4

Easy! Just right clic in your project and select "Unload Project"

Right clic one again and edir your_project.csproj

Search a duplicate tag for the file mentioned in the error message.

Save and right clic to choose "Reload Project"

Right click

Ormazd answered 31/5, 2016 at 17:24 Comment(0)
B
2

I think I encountered the same problem not too long ago. The solution was to remove the subtype from the web.config, i.e:

<Content Include="Web.config">
  <SubType>Designer</SubType>
</Content>

To:

<Content Include="Web.config">
</Content>

Now, those have been added again, I'm not sure why. Searching for more information hasn't cleared it up yet. See: <Subtype>Designer</Subtype> Added then removed by Visual Studio on load/unload

Bannon answered 9/2, 2011 at 9:4 Comment(1)
Yes. It really sucks to have to do this. Hopefully fixed in VS11?Parsimonious
N
2

I know this is old post but I found this better solution which could help others who are currently having this issue.

  • In Solution Explorer, select the file/files specified in the error message or the folder containing these files.

  • Right-click then select Exclude From Project.

  • Click the Refresh button.

  • Select the files or folder again, right-click then select Include In Project.

enter image description here

Nurture answered 22/11, 2019 at 17:52 Comment(0)
T
2

The main clue in the error message is - "Sources". This is a misconfiguration in .csproj file, the build targets are being imported twice. It normally stays at the end of the .csproj file under import. File name is some kind of misleading, I was looking with the file name I can only find it once in the whole project file. When I looked in the import I've got similar to this;

<Import Project="..\..\LonestarWeb\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets" Condition="Exists('..\..\LonestarWeb\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets')" />
<Import Project="\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets" Condition="Exists('..\..\LonestarWeb\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets')" />  

Remove the one you don't need. Reload the solution and you can now compile.

Tensive answered 13/12, 2019 at 23:0 Comment(0)
B
2

Wildcards!

See the example below from a cproj file. The Class.cs Include is already taken care of by the wildcard Include below it so it has now been Included twice. You obviously want to lose the specific Class.cs Include.

<Compile Include="..\Folder\Class.cs">
  <Link>Class.cs</Link>
</Compile>

<!-- lots of things in between ...scroll scroll scroll -->

<Compile Include="..\Folder\*.*">
  <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
Broadsword answered 31/1, 2020 at 3:36 Comment(0)
P
1

I have the same problem and the solution was to shorten and sanitize the directory name (it was a backup one and has date and time separated by a semicolon).

Pulpit answered 26/7, 2011 at 7:37 Comment(0)
N
1

Open the file WcfServiceDomain.csproj with a text editor and look for CrossDomainService.svc.cs

It'll probably be there twice. Just delete one of the lines and the project will work again.

Needleful answered 31/1, 2017 at 11:46 Comment(0)
A
0

I had to delete the class from the project and recreating it again to solve this problem.

Appendicular answered 20/10, 2014 at 16:40 Comment(0)
B
0

The way that I fixed this issue was by going to the location where the file was which was included in the error and find that there was two of the same files. Delete one of them and it should work.

I had to undo the pending changes afterwards as the files then went missing, but after a re-build it worked.

Braden answered 31/3, 2017 at 10:5 Comment(0)
B
0

What I did was that I renamed the file in question. Then cleaned the solution (by clicking on Build > Clean Solution). Then Built the solution.

Then renamed the file to original filename. Then cleaned the solution and built the solution again.

It worked for me. I dont know if it ll work for u.

Bowne answered 16/5, 2017 at 1:13 Comment(0)
R
0

For me I unload the project, Edit .csproj file, search for the filename which was showing in error

<ItemGroup>
    <Compile Include="Controllers\BaseUserContext.cs" />
</ItemGroup>

It was not showing multiple time (BaseUserContext.cs), only 1 tag was there, so I removed it and works without an error.

Roughrider answered 4/6, 2018 at 9:6 Comment(0)
G
0

I had a similar issue. I opened an already existing VS solution for the first time one my machine. This VS solution was not created by a human beeing, but generated from an openAPI-specification using Swagger-Editor.

Initially the solution did not have any problems at all. I could build the solution and I was also able to run the code. The actual issue appeared as soon as I added a new class to any of the projects of the solution (just: 'Right Click' > 'Add' > 'New Item' > 'Class'). No matter what name I chose for that new class I always got the compilererror

The item "MyNewClass.cs" was specified more than once in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter.

Once I removed the class, everything was fine again.

Besides VS, I also have JetBrains Rider (2020.1) on my machine. So I opened the same solution in Rider and added a new class. In Rider, the error did not appear. I was able to add as many classes as I wanted.

In the end, it came down to wildcards, as 'CAD bloke' already mentioned in his answer above.

The original solution generated by the abovementioned Swagger-Editor contains this piece of XML in it's .csproj-file:

  <ItemGroup>
    <Compile Include="**\*.cs" Exclude="obj\**" />
  </ItemGroup>

If I add a new class using VS it becomes this, which in turn causes the error:

  <ItemGroup>
    <Compile Include="**\*.cs" Exclude="obj\**" />
    <Compile Include="Api\NewClass.cs" />
  </ItemGroup>

VS is not aware of the wildcard in use. If I add a class using Rider, the additional <Compile Include="Api\NewClass.cs" /> is not added. Rider is aware of the wildcard!

Seems like the guys at JetBrains are better at dealing with microsofts csproj-format, than microsoft.

How to fix this

To fix this issue in the end, I excluded all source files from the project ('right click' > 'Exclude from Project'). Then I closed the solution and opened the .csproj file in a text editor. I removed the <Compile Include="**\*.cs" Exclude="obj\**" /> from the .csproj-file. After removing the line I opened the solution again in VS and included all source files again ('Show all files' (in solution explorer) > 'right click' > 'Include in project'). Instead of the single wildcard, all files are now defined as

  <ItemGroup>
    <Compile Include="Api\NewClass.cs" />
    <Compile Include="Api\SecondClass.cs" />
    <Compile Include="Api\ThirdClass.cs" />
    ...
  </ItemGroup>

in the .csproj-file.

If you want to reproduce this yourself

  1. Visit: https://swagger.io/tools/swagger-editor/
  2. Click 'Live Demo'
  3. 'Generate Client' > 'csharp'
  4. The step above downloads a zip-file with the VS-solution
  5. Open the solution with VS and add a class
  6. After adding the class you should have the error (unless you used Rider)
Gunpaper answered 4/5, 2020 at 17:27 Comment(0)
G
-2

Only solution was recreate project :/

Gourami answered 21/1, 2011 at 11:39 Comment(3)
I agree. It will really suck if you have a very huge project and you need to recreate your the entire solution! :'(Teirtza
I agree with You, it's realy weak solution. i hope that Jindra solution could help...Gourami
Not a practical solutionOrmazd

© 2022 - 2024 — McMap. All rights reserved.