Skip to content
haf edited this page Oct 25, 2011 · 26 revisions

To simplify the creation of an AssemblyInfo.cs file, for your C#/F#/VB.Net/C++.Net projects, you can use the AssemblyInfoTask. Be sure to require ‘albacore’ at the top of your rakefile, after installing the Albacore gem.

How to use the AssemblyInfoTask

Here is an example of how to use the AssemblyInfoTask


desc "Run a sample assembly info generator"
assemblyinfo :assemblyinfo do |asm|
  asm.version = "0.1.2.3"
  asm.company_name = "a test company"
  asm.product_name = "a product name goes here"
  asm.title = "my assembly title"
  asm.description = "this is the assembly description"
  asm.copyright = "copyright some year, by some legal entity"
  asm.custom_attributes :SomeAttribute => "some value goes here", :AnotherAttribute => "with some data"
  asm.output_file = "lib/spec/support/AssemblyInfo/AssemblyInfo.cs"
end

output_file (required)

The output_file is the name and location of the file that will have the assembly information and attributes written to it. The file with either be created, or overwritten.

If you do not provide an output_file, the rake task will fail and an exception will be logged.

F, [2009-09-28T09:27:37.938000 #7368] FATAL -- : output_file cannot be nil
rake aborted!
output_file cannot be nil

input_file (optional)

The input_file is the name and location of an existing file that contains assembly information and attributes to be written to the output_file. Each attributes can be overridden using the built in AssemblyInfoTask attributes (see below).

Built-In Assembly Attributes (optional)

To simplify the use of certain attributes, the AssemblyInfoTask includes a set of built in attribute settings. Each of these settings are optional. If you do not set them, or if you set them to nil, they will not be written to the output file.

version

The assembly version information. This is typically a “#.#.#.#” format, but can be any valid .NET version # format.

file_version

The file version for the assembly. This is typically a “#.#.#.#” format, but can be any valid .NET version # format.

company_name

The name of the company that owns or is creating / maintaining the assembly in question. For example, “My Company, Inc.”

product_name

The name of the product that this assembly belongs to. For example, “FooBar Widget Maker”

title

The specific title of the assembly in question. This is used to differentiate the assembly’s name from the product’s name. For example the “Widget Factory” assembly may be part of the “FooBar Widget Maker” project.

description

A description of what the assembly in question does. For example, “Builds the Widgets from configuration settings”.

copyright

The copyright information for the assembly in question. For example, “Copyright ©2009 MyCompany, Inc. All Rights Reserved.”

trademark

The trademark information for the assembly in question. For example, “MyProductName™”

com_visible

Determines whether or not an assembly is visible to the COM system, through COM interop. The only valid options for com_visible are true and false. These values must be specified as actual values, not strings.

asm.com_visible = true

com_guid

Sets the guid, as a string, for the COM interop system to use when making your assembly COM visible.

language (Default: C#)

Sets the output language. You can choose between these output languages: F#, C#, C++.Net, VB.Net.

asm.language = "F#"

Alternatively, use these expressions: FSharpEngine.new, CSharpEngine.new, CppCliEngine.new,VbNetEngine.new

asm.lang_engine = FSharpEngine.new

custom_attributes (optional)

This allows you to specify attributes that are not supported through the built-in attributes, listed above. This also allows you to have more creative control over the data that ends up in the parameters for the attribute – if any data is needed, at all.

You can specify multiple custom attributes through a hash literal. The key of the hash will be used as the attribute’s class name. The value of the hash will be used as the parameter that is passed into the attribute constructor.

The example above will generate the following:


[assembly: SomeAttribute("some value goes here")]
[assembly: AnotherAttribute("with some data")]

Empty Constructor Attributes

You can specify a nil value for a custom attribute. This will cause the attribute to be generated with no parameters in the constructor. For example:

asm.custom_attributes :EmptyAttribute => nil

will generate this attribute in the output file

[assembly: EmptyAttribute()]

Literal Value Attributes

You can specify literal values for a custom attribute. This will cause the attribute to be generated with no quotes around the parameter in the constructor. For example:

asm.custom_attributes :BooleanAttribute => true

will generate this attribute in the output file

[assembly: BooleanAttribute(true)]

Namespaces / using statements

By default, the following namespace / using statements are included:

using System.Reflection;
using System.Runtime.InteropServices;

If you need additional namespace / using statements, you can supply them through the custom ‘.namespaces’ setting.

custom namespace/using statements

You can specify as many namespaces as you need, using an array

asm.namespaces 'MyCompany.SomeNamespace', 'Another.Namespace.Here'

This will turn the supplied namespaces into ‘using’ statements at the top of the output file.

Logging

The AssemblyInfoTask uses the built in logging options to provide some potentially useful information at run-time.

assembly info file location

The default information that will be logged includes the location of the assembly info file that is being generated. The path of the file will be fully expanded to include the drive letter and all folders. This can be used to verify that you are generating the file to the correct location.

I, [2009-09-28T08:58:34.801000 #2368]  INFO -- : Generating Assembly Info File At: D:/Dev/Derick-GitHub/test/TestSolution/TestSolution/Properties/AssemblyInfo.cs

verbose mode

If the log_level is set to :verbose, the AssemblyInfoTask will also generate a log message for every attribute that is generated.

D, [2009-09-28T09:01:02.883000 #876] DEBUG -- : Build Assembly Info Attribute: [assembly: AssemblyTitle("my assembly name")]

D, [2009-09-28T09:01:02.884000 #876] DEBUG -- : Build Assembly Info Attribute: [assembly: AssemblyCompany("my company, inc.")]

D, [2009-09-28T09:01:02.884000 #876] DEBUG -- : Build Assembly Info Attribute: [assembly: AssemblyVersion("1.2.3.4")]

YAML configuration

This task supports configuration via an external YAML file. For more information, see the yamlconfig page.