Studio中的重复文件

Studio中的重复文件

本文介绍了csproj文件Visual Studio中的重复文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以某种方式我在解决方案中看到重复的文件。我对其进行了深入研究,结果发现 .csproj 文件中的某些文件有两个条目。这就是为什么显示两个文件实际上是一个文件的原因。我必须在 .csproj 文件中找到所有文件。有什么简单的方法可以从 csproj 中删除​​这些条目?

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?

推荐答案

根据和在StackOverflow上,当TFS(或其他版本控制系统)编辑项目文件,例如在合并操作中。

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.

无论如何,您可能已经打开了一个csproj文件,并看到,文件在以下元素中列出:

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>

上面我链接的问题还提供了对GitHub上的重复数据删除Powershell脚本的引用,尽管我看不到它有什么危害,但我没有尝试过并且不能保证。

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.

这篇关于csproj文件Visual Studio中的重复文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:22