是否有用于检测具有重复 GUID 的 Visual Studio 项目的工具? [英] Is there a tool for detecting Visual Studio projects with duplicate GUIDs?

查看:24
本文介绍了是否有用于检测具有重复 GUID 的 Visual Studio 项目的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建新的 Visual Studio C++ 项目时,有两种方法:运行向导,然后痛苦地更改项目中的所有必要设置,或者只是复制现有项目,重命名其中的所有内容并将文件添加到其中.

When creating new Visual Studio C++ projects there're two ways: either run the wizard and then painfully change all the necessary settings in the project or just copy and existing project, rename everything there and add files into it.

第二个变体很棒,只是 .vcproj 文件存储了一个项目 GUID.当两个或多个项目在一个解决方案中时,此 GUID 用于跟踪项目依赖项和启动项目.如果一个解决方案中的任何两个项目具有相同的 GUID,则可能会出现问题 - 依赖项会丢失,并且启动项目会在下次重新加载解决方案时重置.

The second variant is great except that the .vcproj file stores a project GUID. This GUID is used to track project dependencies and the startup project when two or more projects are in one solution. If any two projects in one solution have identical GUIDs problems can arise - dependencies are lost and the startup prject is reset on next solution reload.

显然需要一种工具来扫描文件系统子树并检测具有相同 GUID 的项目.在我开始写一个之前......是否有一个现成的工具?

Clearly there's a need for a tool that would scan the filesystem subtree and detect projects with identical GUIDs here. Before I start writing one ... is there a ready tool for that?

推荐答案

您可以相对较快地编写工具.我已经为我的雇主这样做了,但他们对代码很吝啬.使用正则表达式时,检测 GUID 很容易".

You can write the tool relatively quickly. I've done so for my employer but they're stingy with code. Detecting a GUID is "easy" when using regular expression.

  1. 扫描感兴趣文件的目录结构.将它们的路径保存在内存列表中.

  1. Scan the directory structure for the files of interest. Keep their paths in a list in memory.

打开每个文件,将全部内容读入内存.

Open each file, reading the entire contents in to memory.

使用您制作的正则表达式查找所有 GUID.

Find all GUIDs with the regular expression you've crafted.

对于遇到的每个 GUID,检查您是否已经在字典中获得了替换 GUID -- 字典将旧 GUID 映射到新 GUID.

For each GUID encountered check if you've already got a replacement GUID in a Dictionary -- the dictionary maps old GUID to new GUID.

  1. 如果您已经有了替换,请替换文本中 Guid 的所有实例.

  1. If you have a replacement already, replace all instances of the Guid in the text.

如果没有替换,请生成一个,将其存储在字典中,然后用新的替换所有实例.

If you don't have a replacement, generate one, store it in the dictionary and then replace all instances with the new one.

  • 写入文件的更改内容.

  • Write the changed contents of the file.

    这就是它的长处和短处.我希望有帮助.

    That's the long and short of it. I hope that helped.

    这篇关于是否有用于检测具有重复 GUID 的 Visual Studio 项目的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆