简体   繁体   English

为什么在Visual Studio中添加解决方案文件夹会更改项目文件,并且有什么方法可以防止这种情况发生?

[英]Why does adding a solution folder in Visual Studio change project files, and is there any way to prevent this?

I am adding a test project to many solutions in our project's primary git repository. 我正在将测试项目添加到项目主git存储库中的许多解决方案中。

In the process, I noticed that adding a "Solution Folder" to the .sln file modifies many of the projects in the solution. 在此过程中,我注意到在.sln文件中添加“解决方案文件夹”会修改解决方案中的许多项目。 I can think of no logical reason this would be the case. 我认为没有逻辑原因会是这种情况。 I am only talking about adding the solution file, before I add the test project. 添加测试项目之前,只是在谈论添加解决方案文件。

All of the projects in the solution are C# projects, if that would make any difference. 解决方案中的所有项目都是C#项目,如果有任何不同的话。

Does anybody know why this is the case. 有谁知道为什么会这样。 Is this intended behavior, or a bug? 这是预期的行为还是错误? Also, is there any way to prevent this from happening? 另外,有什么办法可以防止这种情况的发生?

The two images below highlight the behavior I am talking about: 下面的两个图像突出了我正在谈论的行为:

Before adding the new solution folder : 在添加新的解决方案文件夹之前

在添加解决方案文件夹之前。没有项目更改。

After adding the new solution folder : 添加新的解决方案文件夹后

添加解决方案文件夹之后。项目文件已更改。

As far as I can tell, the changes are meaningless : 据我所知,这些更改是没有意义的

项目文件的更改是没有意义的。

It's a bit weird, but these things happen when people have multiple solutions and fix the casing in one Solution, but not the other. 这有点怪异,但是当人们有多个解决方案并将外壳固定在一个解决方案中而又不在另一个解决方案中时,这些事情就会发生。 When the project file is re-rendered (because a project is added, renamed, solution item changed etc), then it will pick up the corrected casing. 重新渲染项目文件时(由于添加了项目,重命名,更改了解决方案项等),则它将选择更正的大小写。 If the solution file has the 'correct' casing, nothing may change, but if the solution file mismatches it can cause this cascade. 如果解决方案文件的大小写为“正确”,则不会有任何更改,但是如果解决方案文件不匹配,则可能导致级联。

Fixing the casing in one solution may trigger the reverse behavior in another solution. 在一种解决方案中固定外壳可能会在另一种解决方案中触发相反的行为。 Hence, this must be fixed in all solution files at once. 因此,必须立即在所有解决方案文件中修复此问题。 Be careful if you have multiple branches. 如果有多个分支,请小心。

The best way to fix this is to fix the casing issues on the file system, project files and solution files in a single go. 解决此问题的最佳方法是一次性解决文件系统,项目文件和解决方案文件中的大小写问题。 Doing it with a text editor is usually easier than through the Visual Studio project system. 通常,使用文本编辑器比通过Visual Studio项目系统更容易。 Regex search&replace can do wonders here. 正则表达式搜索和替换可以在这里创造奇迹。 Make sure you fix all of these at once: 确保立即修复所有这些问题:

  • The contents of (all of) the solution file(s) (所有)解决方案文件的内容
  • The .*proj file causing the problem 导致问题的.*proj文件
  • The file system path (you may have to change more than the case first for the case change to take). 文件系统路径(为了使大小写更改,您可能必须先更改大小写)。 Also make sure your Version Control system will take the change. 还要确保您的版本控制系统将进行更改。
  • The project references in other .*proj files 其他.*proj文件中的项目引用

When the casing of a single project is fixed, the change may cascade to other project files that reference the problematic project. 固定单个项目的框后,更改可能会级联到引用有问题的项目的其他项目文件中。 The ProjectReference element in the project file has a relative file system path to the problematic project and also captures its name. 项目文件中的ProjectReference元素具有到有问题的项目的相对文件系统路径,并且还捕获其名称。 You can see this clearly in the screenshot you posted: 您可以在发布的屏幕截图中清楚地看到这一点:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM