采用System.Reflection.Emit动态建立程序集如何设置文件的版本信息,描述等信息

 //创建动态程序集,并保存[AssemblyBuilderAccess.RunAndSave]
  1. AssemblyName asmName = new AssemblyName("NXDO.DyORM." + className);
  2. asmName.Version = new Version(NxContext.CurrentVersion);
  3. AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave,"Dlls");

 

//我希望保存输出的程序集带有版本/描述等信息,则代码如下

  1. string strOrmDllTitleAttribute = "ORM动态程序集";
  2. if (this.IsIxDataEntityChildren) strOrmDllTitleAttribute += ",实体类映射";
  3. else if (this.IsIxDataSPChildren) strOrmDllTitleAttribute += ",存储映射";
  4. else strOrmDllTitleAttribute += ",部分字段映射";
  5. CustomAttributeBuilder attr1 = new CustomAttributeBuilder(typeof(AssemblyTitleAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { strOrmDllTitleAttribute });
  6. CustomAttributeBuilder attr2 = new CustomAttributeBuilder(typeof(AssemblyDescriptionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { classT.Name + "接口实现类" });
  7. CustomAttributeBuilder attr3 = new CustomAttributeBuilder(typeof(AssemblyConfigurationAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "" });
  8. CustomAttributeBuilder attr4 = new CustomAttributeBuilder(typeof(AssemblyCompanyAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "ITBabySoftware" });
  9. CustomAttributeBuilder attr5 = new CustomAttributeBuilder(typeof(AssemblyProductAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "NXDO.Data.DyORM." + classT.Name });
  10. CustomAttributeBuilder attr6 = new CustomAttributeBuilder(typeof(AssemblyCopyrightAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "ITBabySoftware @Copyright2005-" + System.DateTime.Now.Year.ToString() });
  11. CustomAttributeBuilder attr7 = new CustomAttributeBuilder(typeof(AssemblyTrademarkAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "http://blog.csdn.net/javasuki" });
  12. CustomAttributeBuilder attr8 = new CustomAttributeBuilder(typeof(AssemblyCultureAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "" });
  13. CustomAttributeBuilder attr9 = new CustomAttributeBuilder(typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { NxContext.CurrentVersion });
  14. CustomAttributeBuilder attr10 = new CustomAttributeBuilder(typeof(AssemblyFileVersionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { NxContext.CurrentVersion });
  15. assembly.SetCustomAttribute(attr1);
  16. assembly.SetCustomAttribute(attr2);
  17. assembly.SetCustomAttribute(attr3);
  18. assembly.SetCustomAttribute(attr4);
  19. assembly.SetCustomAttribute(attr5);
  20. assembly.SetCustomAttribute(attr6);
  21. assembly.SetCustomAttribute(attr7);
  22. assembly.SetCustomAttribute(attr8);
  23. assembly.SetCustomAttribute(attr9);
  24. assembly.SetCustomAttribute(attr10);
  25. assembly.DefineVersionInfoResource();   //以上程序集属性将被追加到文件信息中

 

图例如下:采用System.Reflection.Emit动态建立程序集如何设置文件的版本信息,描述等信息_第1张图片

如需转载请注明出处,http://blog.csdn.net/javasuki

联系邮件:[email protected]

 

你可能感兴趣的:(采用System.Reflection.Emit动态建立程序集如何设置文件的版本信息,描述等信息)