How to replace all the existing GUIDs with new one from the Visual Studio solution/project?

1.2k views Asked by At

I have a Windows application developed with C# and C++ so it has multiple .cs and .cpp files. Now many of the .cs file has the GUID in below format :

[Guid( "D01A42F5-FD89-4c8f-8065-726AD4363411" )]

There are a huge numbers of GUIDs present in my projects. Now I am upgrading the current 32 bit application to 64bit so don't want to have same GUIDs for both the applications.

Is there anyway to replace all the GUIDs without doing it manually? I knew about the options Tools--> Create GUID but for this case I need to replace it manually in all those class files.

Edit: Below two entries are getting conflicted and overrided with later installed application.

Computer\HKEY_CLASSES_ROOT\namespacedll\CLSID

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\namespacedll\CLSID

2

There are 2 answers

3
TomTom On

Is there anyway to replace all the GUIDs without doing it manually?

Nope.

I also do not understand why this is a problem. 32 and 64 bit generally do not interact, so unless you can make a real point by example or a link to documentation, this looks to me like "busy work" - creating a lot of work with no need.

0
ProgrammingLlama On

My personal approach would be to create an application to read every single project file, regex match/replace each individual GUID with a freshly-generated one.

There is a simpler approach you could take that is unlikely to produce duplicates, and that is to swap and shift parts of the existing GUID values using a regex replace.

So you could match everything with this:

([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])\-([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])\-4([0-9A-F])([0-9A-F])([0-9A-F])\-([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])\-([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])

And then replace it with a shifted/swapped version:

$31$1$30$2$29$3$28$4-$27$5$26$6-4$25$7$24-$8$23$9$22-$10$21$11$20$12$19$13$18$14$17$15$16

Note that this will only work with version 4 GUIDs because we're expecting the static 4 version identifier. Also note that it doesn't actually generate a new GUID; it simply rearranges the existing one. It takes the last character, then the first, then the next last, and then the next last, and so on. The plus side to this is that all GUID values that are currently the same will be the same as each other once the transformation is applied.

Example