0

有时,ILMerge 已更改,现在它删除了与安全相关的属性。

问题:

  • 为什么要实现这个功能?
  • 和/或是否可以(安全地)从工具的私有版本(用于创建已发布的程序集)中删除它?

源代码中的实现在这里,fwiw:

  #region Deal with [ComVisible] and security attributes
  var thisAssemblyIsComVisible = GetComVisibleSettingForAssembly(a);
  AttributeNode assemblyComVisibleAttribute = null;
  if (thisAssemblyIsComVisible != targetAssemblyIsComVisible) {
    InstanceInitializer ctor = SystemTypes.ComVisibleAttribute.GetConstructor(SystemTypes.Boolean);
    assemblyComVisibleAttribute = new AttributeNode(new MemberBinding(null, ctor), new ExpressionList(new Literal(thisAssemblyIsComVisible, SystemTypes.Boolean)));
  }
  for (int i = 0, n = a.Attributes == null ? 0 : a.Attributes.Count; i < n; i++) {
    AttributeNode aNode = a.Attributes[i];
    if (aNode == null) continue;
    if (aNode.Type == SystemTypes.ComVisibleAttribute) {
      a.Attributes[i] = null;
      continue;
    }
    if (aNode.Type == SystemTypes.SecurityCriticalAttribute
      || aNode.Type == SystemTypes.SecurityTransparentAttribute
      || aNode.Type == SystemTypes.AllowPartiallyTrustedCallersAttribute
      || aNode.Type.FullName.Equals("System.Security.SecurityRules")
      ) {
      WriteToLog("Assembly level attribute '{0}' from assembly '{1}' being deleted from target assembly",
        aNode.Type.FullName, a.Name);
      a.Attributes[i] = null;
      continue;
    }
  }
  #endregion

它会给某些人带来问题:

我想使用 ILMerge 构建具有该AllowPartiallyTrustedCallers属性的程序集。我曾经这样做(使用旧版本的 ILMerge)并且不知道为什么我不能了。

我大概可以通过根本不使用 ILMerge 来做到这一点(即将所有源代码放入一个项目中,而不是构建多个要合并的项目),所以我看不出有什么危害,即为什么 ILMerge 将不再做。

4

1 回答 1

1

我现在改用ILRepack,它的命令行与 ILMerge 相同,并且没有此限制。

于 2017-12-12T22:02:31.997 回答