     fileprivate func generateBuildRules(_ buildRule: PBXBuildRule,
                                         identifiers: [String]) throws {
         var identifiers = identifiers
-        identifiers.append(String(describing: buildRule))
         if let name = buildRule.name {
             identifiers.append(name)
         }
 
         // Build rule
-        if buildRule.reference.temporary {
-            buildRule.reference.fix(generate(identifiers: identifiers))
-        }
-    }
-
-    /// Given a list of identifiers, it returns a deterministic reference.
-    /// If the reference already exists in the project (very unlikely), it'll
-    /// make sure the generated reference doesn't collide with the existing one.
+        buildRule.fixReference(identifiers: identifiers)
+    }
+}
+
+extension PBXObject {
+
+    /// Given a list of identifiers, it generates a deterministic reference.
     ///
     /// - Parameter identifiers: list of identifiers used to generate the reference of the object.
     /// - Returns: object reference.
-    fileprivate func generate(identifiers: [String]) -> String {
-        return identifiers.joined(separator: "-").md5.uppercased()
+    func fixReference(identifiers: [String]) {
+        if reference.temporary {
+            let identifiers = [String(describing: type(of: self))] + identifiers
+            let value = identifiers.joined(separator: "-").md5.uppercased()
+            reference.fix(value)
+        }
     }
 }

    func generateProjectAndTargets(project: PBXProject,
                                   identifiers: [String]) {
        // Project
        if project.reference.temporary {
            project.reference.fix(generate(identifiers: identifiers))
        }

        // Targets
        let targets: [PBXTarget] = project.targetReferences.objects()
        targets.forEach { target in

            var identifiers = identifiers
            identifiers.append(String(describing: target))
            identifiers.append(target.name)

            if target.reference.temporary {
                target.reference.fix(generate(identifiers: identifiers))
            }
        }
    }


            let targetProxy = targetDependency.targetProxy,
            let remoteGlobalIDReference = targetProxy.remoteGlobalIDReference {
            var identifiers = identifiers
            identifiers.append(remoteGlobalIDReference.value)
            targetProxy.fixReference(identifiers: identifiers)
        }

        // Target dependency
