19.1 Setting Informational Assembly Attributes

 <  Day Day Up  >  

You want to have the compiler embed in an assembly attributes that identify the software product and provide other useful information about the origin of the assembly.


Technique

If you have a project created with VS.NET, then navigate to the AssemblyInfo.cs file that VS.NET created for you. Identify the lines in this code that look something like this:

 
 [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] 

Simply add the information to be placed in the assembly inside the quotes. For example, to change the company name to Sams Publishing and the product name to C# Cookbook Sample, amend those lines to

 
 [assembly: AssemblyCompany("Sams Publishing")] [assembly: AssemblyProduct("C# Cookbook Sample")] 

Then simply rebuild the project.

If your project was not created with VS.NET, then you most likely won't have an AssemblyInfo.cs file. In that case, simply add the required attribute definitions to any file in the project. Note that there is no special significance in the AssemblyInfo.cs file; VS.NET creates this file and places assembly attributes in it so all the assembly attributes for a project are in one place. You can declare the assembly attributes in any file in your code (although each one should be declared only once in the project).

Comments

The preceding code uses standard C# syntax for declaring custom attributes. Note that as part of the process of compiling the project, the compiler actually instantiates the attributes you declare and executes the appropriate constructors. Any errors in the data you supply for an attribute that would prevent that attribute from being constructed are therefore picked up at compile time.

Also bear in mind that executable assemblies cannot be localized. Hence, you'll get a compilation error if you supply any culture information for a project that will be compiled into an .exe assembly.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net