Skip to content
Henrik edited this page Aug 21, 2014 · 1 revision

Create or version an Assembly Info file for all .NET project types. This task includes a set of built-in, optional properties corresponding to commonly set attributes.

desc "Create a sample assembly info file"
assemblyinfo :version do |cmd|
  cmd.version = "1.0.0"
  cmd.company_name = "ACME"
  cmd.product_name = "Foo Suite"
  cmd.title = "The Foo Assembly"
  cmd.description = "A useful description of the assembly."
  cmd.copyright = "(c) 2013 by ACME"
  cmd.output_file = "path/to/AssemblyInfo.cs"
end

Required Parameters

Output File

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.

output_file = "path/to/AssemblyInfo.cs"

Optional Parameters

Input File

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 attribute can be overridden using the built in properties of this task.

input_file = "path/to/AssemblyInfo.cs"

Version, File Version, & Informational Version

The assembly, file version, and informational version information.

version = "1.0.0"
file_version = "1.0.0"
informational_version = "1.0.0+build.9000"

Company Name, Product Name, Copyright, & Trademark

The name of the company that owns the assembly, the name of the product that it belongs to, the copyright date/holder, and any trademark that may exist.

company_name = "ACME"
product_name = "Foo Suite"
copyright = "(c) 2013 by ACME"
trademark = "Foo Suite (tm)"

Title & Description

The title of the assembly differentiates the assembly's name from the product's name.

title = "Widget Factory"
description = "Builds the Widgets from configuration settings."

Com Visible & Com GUID

Determines whether or not an assembly is visible to the COM system, through COM interop.

com_visible
com_guid = "00000000-0000-0000-0000-000000000000"

Language

Choose an output language: F#, C#, C++.Net, VB.Net. Defaults to C#.

lanugage = "VB.Net"

Custom Attributes

This 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.

custom_attributes = {
  :FooAttribute => "foo", 
  :BarAttribute => "bar" 
}

The example above will produce the following for a C# assembly info

[assembly: FooAttribute("foo")]
[assembly: BarAttribute("bar")]

You can specify nil for a custom attribute value to generate no parameters in the constructor. For example, this

custom_attributes = {:EmptyAttribute => nil}

generates

[assembly: EmptyAttribute()]

You can specify literal values, without quotes, for a custom attribute, too. For example, this

custom_attributes = {:BooleanAttribute => true}

generates

[assembly: BooleanAttribute(true)]

Namespaces

By default, the following namespaces are imported: System.Reflection, System.Runtime.InteropServices. You can specify more, as an array, using the namespaces property.

namespaces = [
  "Acme.FooBar.SomeNamespace",
  "Acme.BarBaz.SomeOtherNamespace"
]

Initial Comments

initial_comments = [
  "// something required by your company lawyers",
  "// can go here, like this"
]

Guidance

Existing AssemblyInfo Files

If you have an existing, common assembly info file it probably has all of the company, description, and copyright information stored in it already. You probably only want to overwrite the version and file version. Just supply the same filename/location for the input and output file. Any property specified will be overwritten, the rest of the file will remain unchanged.

assemblyinfo :version do |cmd|
  cmd.input_file = cmd.output_file = "path/to/AssemblyInfo.cs"
  cmd.version = cmd.file_version = "1.0.0"
end

Different Language Files

If you have mixed or non-default assembly info files, you have to set the appropriate language "engine". Unfortunately, we didn't provide automatic selection (which would be simple, based on these techniques). For one non-default file, it's a simple assignment.

assemblyinfo :version do |cmd|
  cmd.input_file = cmd.output_file = "path/to/AssemblyInfo.vb"
  cmd.language = "VB.Net"
end

For a mixed solution, you might start by writing each task, but that's not recommended.

task :version => [:version_cs, :version_vb]

assemblyinfo :version_cs do |cmd|
  # ...
end

assemblyinfo :version_vb do |cmd|
  cmd.language = "VB.Net"
  # ...
end

You'll want to use a FileList pattern and create a task per file, assigning the language engine if it's non-default.

assemblyinfos = FileList["wildcard/paths/to/AssemblyInfo.*"]

assemblyinfos.each |file|
  assemblyinfo file do |cmd|
    cmd.input_file = cmd.output_file = file
    cmd.language = "VB.Net" if File.extname(file) == ".vb"
    # ...
  end
end

# this task depends on the array of filenames, which we've
# assigned as the individual task names, above.
desc "Version all of the assemblies"
task :version => assemblyinfos
Clone this wiki locally