采用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();   //以上程序集属性将被追加到文件信息中

 

图例如下:

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

联系邮件:javasuki@hotmail.com

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值