/// <summary> /// Adds or updates an existing <c>System.Reflection.AssemblySignatureKeyAttribute</c> /// attribute. This attribute is used in enhanced strong naming with key migration. /// See http://msdn.microsoft.com/en-us/library/hh415055.aspx /// </summary> /// <param name="identityPubKey">Identity public key</param> /// <param name="identityKey">Identity strong name key pair</param> /// <param name="signaturePubKey">Signature public key</param> public void UpdateOrCreateAssemblySignatureKeyAttribute(StrongNamePublicKey identityPubKey, StrongNameKey identityKey, StrongNamePublicKey signaturePubKey) { var manifestModule = ManifestModule; if (manifestModule == null) return; // Remove all existing attributes var ca = CustomAttributes.ExecuteLocked<CustomAttribute, object, CustomAttribute>(null, (tsList, arg) => { CustomAttribute foundCa = null; for (int i = 0; i < tsList.Count_NoLock(); i++) { var caTmp = tsList.Get_NoLock(i); if (caTmp.TypeFullName != "System.Reflection.AssemblySignatureKeyAttribute") continue; tsList.RemoveAt_NoLock(i); i--; if (foundCa == null) foundCa = caTmp; } return foundCa; }); if (IsValidAssemblySignatureKeyAttribute(ca)) ca.NamedArguments.Clear(); else ca = CreateAssemblySignatureKeyAttribute(); var counterSig = StrongNameKey.CreateCounterSignatureAsString(identityPubKey, identityKey, signaturePubKey); ca.ConstructorArguments[0] = new CAArgument(manifestModule.CorLibTypes.String, new UTF8String(signaturePubKey.ToString())); ca.ConstructorArguments[1] = new CAArgument(manifestModule.CorLibTypes.String, new UTF8String(counterSig)); CustomAttributes.Add(ca); }
/// <summary> /// Adds or updates an existing <c>System.Reflection.AssemblySignatureKeyAttribute</c> /// attribute. This attribute is used in enhanced strong naming with key migration. /// See http://msdn.microsoft.com/en-us/library/hh415055.aspx /// </summary> /// <param name="identityPubKey">Identity public key</param> /// <param name="identityKey">Identity strong name key pair</param> /// <param name="signaturePubKey">Signature public key</param> public void UpdateOrCreateAssemblySignatureKeyAttribute(StrongNamePublicKey identityPubKey, StrongNameKey identityKey, StrongNamePublicKey signaturePubKey) { if (ManifestModule == null) { return; } // Remove all existing attributes CustomAttribute ca = null; for (int i = 0; i < CustomAttributes.Count; i++) { var caTmp = CustomAttributes[i]; if (caTmp.TypeFullName != "System.Reflection.AssemblySignatureKeyAttribute") { continue; } CustomAttributes.RemoveAt(i); i--; if (ca == null) { ca = caTmp; } } if (IsValidAssemblySignatureKeyAttribute(ca)) { ca.NamedArguments.Clear(); } else { ca = CreateAssemblySignatureKeyAttribute(); } var counterSig = StrongNameKey.CreateCounterSignatureAsString(identityPubKey, identityKey, signaturePubKey); ca.ConstructorArguments[0] = new CAArgument(ManifestModule.CorLibTypes.String, new UTF8String(signaturePubKey.ToString())); ca.ConstructorArguments[1] = new CAArgument(ManifestModule.CorLibTypes.String, new UTF8String(counterSig)); CustomAttributes.Add(ca); }