问题
Somehow I am seeing duplicate files in my solution. I dig into it and found that somehow, there are two entries for some files in .csproj
file. That's why two files are shown that is actually one file. I have to find for all the files in .csproj
file. Is there any easy way to remove those entries from csproj
? And also can anyone let me know the cause of this?
回答1:
As per this question and this other one on StackOverflow, this might happen when TFS (or other version control systems) edit a project file e.g. during a merge operation.
Anyway, you have probably opened a csproj file and seen that it's just an XML, with files being listed in elements like those below:
<ItemGroup>
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\ContactsController.cs" />
<Compile Include="Controllers\HomeController.cs" />
...
</ItemGroup>
One answer to the question I linked above also provides a reference to a deduplication Powershell script on GitHub, which I haven't tried and cannot guarantee for, although I don't see what harm it could do.
If your files are not too many, you can just look for the following string
.cs" />
with a text editor like PsPad, have it list the results and remove double entries by hand. Of course, before doing anything, backup your file.
Another solution involves selecting all duplicated files in your project, clicking "Exclude from project" and then "Show all files" and include them by hand.
来源:https://stackoverflow.com/questions/49691209/duplicate-files-in-csproj-file-visual-studio