项目GUID不断变化
我们有一个 VS2008 解决方案,我注意到发生了一些奇怪的事情:
一些项目引用了同一解决方案中定义的其他项目(作为项目引用添加)。这是前一段时间完成的。
直接从 VS 构建效果很好。
从 MSBUILD 构建失败。
我已删除项目引用并重新添加它,并且我注意到项目的 GUID 已更改。现在可以使用 MSBUILD 进行构建了。
问题是,我现在必须检查所有项目并验证这一点。
而且,我不知道为什么会发生这种情况(为什么项目 GUID 与以前不同,并且不确定这种情况是否会再次发生)。
这可能是什么原因造成的?
We have a VS2008 solution and i've noticed something weird happening:
some projects refer other projects that are defined in the same solution (added as project references). This was done some time ago.
Building straight from VS works fine.
Building from MSBUILD fails.
I have removed the project reference and re added it, and i've noticed that the project's GUID is changed. Building from MSBUILD now works.
Problem is, i now have to go over all projects and verify this.
Moreover, i have no idea why this occured (why is the project GUID different from what it was before, and not sure if this may happen again).
What could be the cause of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也在 Visual Studio 2013 中看到了这个问题,并且它不需要发生源代码管理集成。
当我在多个解决方案中拥有相同的项目时,我偶尔会遇到这种情况,每个解决方案对该项目使用不同的 GUID,并相应地更新项目。解决方案是手动修改 .sln 文件以使它们同步。这个答案归功于唐春生。
首先使用记事本打开解决方案文件 (.sln),然后查看其中的项目引用。格式如下:
每个项目的第二个 GUID 是对共享项目的引用。
要解决该问题,请为您的共享项目选择一个 GUID;确保打开它的所有解决方案在其解决方案文件中都具有该单个 GUID,从而具有相同的 GUID。 (请在进行这些更改之前备份您的文件)
https://social.msdn.microsoft.com/Forums/en-US/1d632940-cc1d-49d5-a64c-d3e999216cbd/cant-avoid-the-projectguid-from-being-changed-in-csproj-file?论坛=csharpide
I also see this problem in Visual Studio 2013, and it does not require Source Control integration to occur.
It happens to me occasionally when I have the same project in multiple solutions, each solution uses a different GUID for that project, and updates the project accordingly. The solution is to manually modify the .sln files to get them in sync. Credit for this answer goes to Chunsheng Tang.
First open the solution file (.sln) with notepad and check out the project references there. The format is like this:
The second GUID for each project is the reference to the shared project.
To solve the problem, select a single GUID for your shared project; Make sure all the solutions that open it have that single thus the same GUID in their solution files. (Please backup your files before making these changes)
https://social.msdn.microsoft.com/Forums/en-US/1d632940-cc1d-49d5-a64c-d3e999216cbd/cant-avoid-the-projectguid-from-being-changed-in-csproj-file?forum=csharpide
ProjectGuid 由于与源代码控制系统(如 TFS)集成而发生变化。例如,如果其他人打开文件,就会发生这种情况。
这里描述了解决方法:
http://social.msdn.microsoft.com/Forums/en-US/csharpide/thread/1d632940-cc1d-49d5-a64c-d3e999216cbd
The ProjectGuid changes because of integration with a source control system, like TFS. Happens if other people open the files for example.
There is workaround described here:
http://social.msdn.microsoft.com/Forums/en-US/csharpide/thread/1d632940-cc1d-49d5-a64c-d3e999216cbd
对我来说,问题是解决方案文件之一中有重复的 GUID。在我的安装程序的 .sln 中,我发现配置项目 GUID(到处使用)和安装程序项目 GUID(特定于解决方案)是相同的。打开解决方案导致 VS 在项目文件中更改其中之一的 GUID,尽管在解决方案文件中没有明显显示。碰巧的是,它总是选择共同的那个,造成最大的悲伤。修复方法是为安装程序项目创建一个新的 GUID,然后手动将所有其他解决方案文件编辑回 Config 项目的正确 GUID。
我不知道这是怎么发生的,因为我从来没有复制项目来创建它们。
The problem for me turned out to be a duplicate GUID in one of the solution files. Inside the .sln for my installer I found that the Config project GUID (used all over the place) and the Installer project GUID (specific to the solution) were identitical. Opening the solution caused VS to change the GUID for one of them in the project file, though not apparently in the solution file. As it happens it always chose the shared one causing maximum grief. The fix was to create a new GUID for the installer project, and manually edit all the other solution files back to the correct GUID for the Config project.
I've no idea how this came about since I don't ever copy projects to create them.
解决方案文件从项目文件中获取项目 GUID。您是否从早期版本的 VS 升级了解决方案/项目?如果解决方案文件中的guid不断变化,可能是因为项目文件根本没有guid,所以每次打开解决方案时VS都会创建一个新的guid。我认为这是 VS 升级机制中的一个错误,但没有人问我。通过在项目文件中添加 guid 来解决该问题,如下所示:
再次打开解决方案,然后将项目 guid 最后一次更改为这个新的 guid。指南将永远不会再改变。
The solution file gets the project guid from the project file. Did you upgrade the solution/project from an earlier version of VS? If the guid in the solution file keeps changing, it could be because the project file doesn't have a guid at all, so VS makes up a new one each time the solution is opened. I'd call this a bug in the VS upgrade mechanism, but no one asked me. Fix the problem by adding a guid in your project file like this:
Open the solution one more time and let the project guid change one last time to this new guid. The guid will never change again.
关于解决方法:可以在解决方案文件 (.sln) 中的多个位置引用 GUID。请记住替换对此 GUID 的所有引用,而不仅仅是解决方法中提到的引用(解决方法已锁定 - 无法在那里留下评论,所以我不得不回答这篇文章)。
Regarding the workaround: the GUID may be referenced several places in the solution file (.sln). Remember to replace all references to this GUID, not just the one mentioned in the workaround (workaround is locked - unable to leave a comment there, so I had to answer this post instead).
如果您在同一解决方案中有两个具有相同 guid 的项目,则会发生这种情况,VS 将为其中之一分配一个新的 guid。
当构建具有新项目的新解决方案时,可能会发生这种情况,并且如果您插入共享项目,它们可能具有与新项目相同的 guid。
问题是所有其他已经插入共享项目的解决方案都必须再次更改 guid,这很烦人。
一个简单的解决方案,而不是手动编辑解决方案/项目文件:
只需删除项目,然后首先插入共享项目,然后插入新项目。因此,VS 为新项目提供了一个新的(而不是重复的)guid,并且不会强制更改共享项目的 guid。
...“全球唯一标识符”主题就这么多;-)
This happens if you have two projects with the same guid in the same solution, VS will assign a new guid to one of them.
And that can be happen when a new solution with a new Project is build and if you insert shared projects they may have a guid that is the same like the new project.
The problem is that all other solutions which have also the shared project already inserted have to change the guid again and thats annoyingly.
A simple Solution instead of editing the solution-/project-files by hand:
Just remove the projects and then insert the shared projects FIRST and AFTER THAT insert the NEW project. So VS gives a new - not duplicate - guid to the new project and is not forced to change the guid of the shared projects.
... so much for the topic "Globally Unique Identifier" ;-)