1、前言 html
.net工程的Properties文件夾下自動生成一個名爲AssemblyInfo.cs的文件,通常狀況下咱們不多直接改動該文件。但咱們實際上經過另外一個形式操做該文件。那就是經過在鼠標右鍵點擊項目的屬性進入「應用程序」->「程序集信息」,而後修改信息。框架
2、做用 post
經過特性(Attribute)來設置程序集(dll文件)的常規信息,供查看或做爲配置信息供程序內部使用。spa
3、詳解 .net
對生成的dll文件右鍵點擊屬性,便可查看到上述信息。3d
assembly: 表示特性以程序集做爲做用範圍。調試
4、讀取assembly特性 code
以讀取 [assembly:AssemblyProduct("")] 爲例子htm
Type t = typeof(Program); AssemblyProductAttribute productAttr = t.Assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), true)[0] as AssemblyProductAttribute; Console.WriteLine(productAttr.Product);
5、注意點
blog
1. [assembly:AssemblyProduct("")] 特性不限於在AssemblyInfo.cs文件中使用,而是能夠在任何的.cs文件中使用。
2. 對於同一個特性,程序集中僅能設置一次,不然編譯時將報錯。
示例:
[assembly:AssemblyProduct("")] namespace{ public class Demo{ } }
6、總結
如今回頭看《.Net魔法堂:log4net詳解》當中的那句 [assembly:log4net.Config.XmlConfigurator(Watch=true)] 應該就清晰多了。其實就是配置log4net框架從哪裏讀配置文件而已,固然這句也能夠寫到AssemblyInfo.cs文件中統一管理咯!
尊重原創,轉載請註明來自:http://blog.csdn.net/qq395537505點擊打開連接
7、參考
http://www.itwis.com/html/net/aspnet/20091211/7123.html
若是您以爲本文的內容有趣就掃一下吧!捐贈互勉!