.net 读取项目AssemblyInfo.cs属性值
2012-03-31 11:57
344 查看
.net 读取项目AssemblyInfo.cs属性值的实现代码。
We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. It would be a great stop to write all such things in the assemblyinfo.cs (because it needs to completely describe the assembly that it
is intended to serve for) You can define your About form of the application entirely using the AssemblyInfo.cs
How to use the following info:
AssemblyInfo ainfo = new AssemblyInfo();
frmAbout.Text = ainfo.Title;
frmAbout.menuAbt.Text = string.Format("&About{0}..",ainfo.Title);
frmAbout.Text = "About " + this.Owner.Text;
frmAbout.Icon = this.Owner.Icon;
//You can set the icon like this on the abt form.
frmAbout.pictureBox1.Image = this.Owner.Icon.ToBitmap();
frmAbout.lblTitle.Text = ainfo.Title;
frmAbout.lblVersion.Text = ainfo.Version;
frmAbout.lblCopyright.Text = ainfo.Copyright;
frmAbout.lblDescription.Text = ainfo.Description;
frmAbout.lblCodebase.Text = ainfo.CodeBase;
下面是具体的实现代码。
详细出处参考:http://www.jb51.net/article/18650.htm
We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. It would be a great stop to write all such things in the assemblyinfo.cs (because it needs to completely describe the assembly that it
is intended to serve for) You can define your About form of the application entirely using the AssemblyInfo.cs
How to use the following info:
AssemblyInfo ainfo = new AssemblyInfo();
frmAbout.Text = ainfo.Title;
frmAbout.menuAbt.Text = string.Format("&About{0}..",ainfo.Title);
frmAbout.Text = "About " + this.Owner.Text;
frmAbout.Icon = this.Owner.Icon;
//You can set the icon like this on the abt form.
frmAbout.pictureBox1.Image = this.Owner.Icon.ToBitmap();
frmAbout.lblTitle.Text = ainfo.Title;
frmAbout.lblVersion.Text = ainfo.Version;
frmAbout.lblCopyright.Text = ainfo.Copyright;
frmAbout.lblDescription.Text = ainfo.Description;
frmAbout.lblCodebase.Text = ainfo.CodeBase;
下面是具体的实现代码。
using System; using System.Reflection; using System.Runtime.CompilerServices; [assembly: AssemblyTitle("Demo Title")] [assembly: AssemblyDescription("Demo app that reads from the Assembly Info file description")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("World Company")] [assembly: AssemblyProduct("Not for commercial use.")] [assembly: AssemblyCopyright("open source (US)")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: CLSCompliant(true)] [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.1.1")] # region "Class to get the information for AboutForm" /* This class uses the System.Reflection.Assembly class to access assembly meta-data. * This class is not a normal feature of AssmblyInfo.cs */ /// <summary> /// AssemblyInfo class. /// </summary> public class AssemblyInfo { //Used by functions to access information from Assembly Attributes /// <summary> /// myType. /// </summary> private Type myType; /// <summary> /// Initializes a new instance of the <see cref="AssemblyInfo"/> class. /// </summary> public AssemblyInfo() { //Shellform here denotes the actual form. myType = typeof(ShellForm); } /// <summary> /// Gets the name of the assembly. /// </summary> /// <value>The name of the assembly.</value> public String AssemblyName { get { return myType.Assembly.GetName().Name.ToString(); } } /// <summary> /// Gets the full name of the assembly. /// </summary> /// <value>The full name of the assembly.</value> public String AssemblyFullName { get { return myType.Assembly.GetName().FullName.ToString(); } } /// <summary> /// Gets the code base. /// </summary> /// <value>The code base.</value> public String CodeBase { get { return myType.Assembly.CodeBase; } } /// <summary> /// Gets the copyright. /// </summary> /// <value>The copyright.</value> public String Copyright { get { Type att = typeof(AssemblyCopyrightAttribute); object[] r = myType.Assembly.GetCustomAttributes(att, false); AssemblyCopyrightAttribute copyattr = (AssemblyCopyrightAttribute)r[0]; return copyattr.Copyright; } } /// <summary> /// Gets the company. /// </summary> /// <value>The company.</value> public String Company { get { Type att = typeof(AssemblyCompanyAttribute); object[] r = myType.Assembly.GetCustomAttributes(att, false); AssemblyCompanyAttribute compattr = (AssemblyCompanyAttribute)r[0]; return compattr.Company; } } /// <summary> /// Gets the description. /// </summary> /// <value>The description.</value> public String Description { get { Type att = typeof(AssemblyDescriptionAttribute); object[] r = myType.Assembly.GetCustomAttributes(att, false); AssemblyDescriptionAttribute descattr = (AssemblyDescriptionAttribute)r[0]; return descattr.Description; } } /// <summary> /// Gets the product. /// </summary> /// <value>The product.</value> public String Product { get { Type att = typeof(AssemblyProductAttribute); object[] r = myType.Assembly.GetCustomAttributes(att, false); AssemblyProductAttribute prodattr = (AssemblyProductAttribute)r[0]; return prodattr.Product; } } /// <summary> /// Gets the title. /// </summary> /// <value>The title.</value> public String Title { get { Type att = typeof(AssemblyTitleAttribute); object[] r = myType.Assembly.GetCustomAttributes(att, false); AssemblyTitleAttribute titleattr = (AssemblyTitleAttribute)r[0]; return titleattr.Title; } } /// <summary> /// Gets the version. /// </summary> /// <value>The version.</value> public String Version { get { return myType.Assembly.GetName().Version.ToString(); } } } # endregion 详细出处参考:http://www.jb51.net/article/18650.htm
详细出处参考:http://www.jb51.net/article/18650.htm
相关文章推荐
- c# AssemblyInfo 解释 .net 读取项目AssemblyInfo.cs属性值
- .net 读取项目AssemblyInfo.cs属性值
- 使用log4net-1.2.0-beta8 在项目的AssemblyInfo.cs文件中设置
- 解决 vs 2010 中新建项目时 , AssemblyInfo.cs 中出错的问题
- .Net魔法堂:AssemblyInfo.cs文件详解
- .NET项目中的AssemblyInfo文件的作用
- .net 开发中的AssemblyInfo.cs文件的作用
- .net 开发中的AssemblyInfo.cs文件的作用
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题
- 提取assemblyinfo.cs文件里的guid值
- .net 读取 project mpp 项目文件
- get assemblyinfo.cs version info in asp.net 2.0
- AssemblyInfo.cs文件的作用
- AssemblyInfo.cs文件的作用
- AssemblyInfo.cs文件的作用
- snk文件和AssemblyInfo.cs文件的作用[转]
- 1.获得项目中info.plist文件的内容 2.沙盒的数据存储及读取 3.控制器view的高度和状态栏statusBar的关系 4.[UIScreen mainScreen].application
- snk文件和AssemblyInfo.cs文件的作用
- AssemblyInfo.cs文件的作用