AssemblyInfo Class

MSBuild Extension Pack

AssemblyInfo Class MSBuild Extension Pack Help 4.0.12.0
The AssemblyInfo task provides a way to manipulate the content of AssemblyInfo files at build time. It works with C#, VB, and J# AssemblyInfo files.

This task is based on the AssemblyInfo task written by Neil Enns (http://code.msdn.microsoft.com/AssemblyInfoTaskvers). It is used here with permission.

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPack.FrameworkAssemblyInfo

Namespace: MSBuild.ExtensionPack.Framework
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The AssemblyInfo type exposes the following members.

Constructors

  NameDescription
Public methodAssemblyInfo
Top
Methods

  NameDescription
Public methodExecute
Executes the AssemblyInfo task.
(Overrides TaskExecute.)
Top
Properties

  NameDescription
Public propertyCode exampleAssemblyBuildNumber
The build number of the assembly.
Public propertyCode exampleAssemblyBuildNumberFormat
The format string to apply when converting the build number to a text string.
Public propertyCode exampleAssemblyBuildNumberType
The type of update to use when setting the AssemblyBuildNumber property.
Public propertyCode exampleAssemblyCompany
The company that created the assembly.
Public propertyCode exampleAssemblyConfiguration
The configuration of the assembly.
Public propertyCode exampleAssemblyCopyright
The copyright information for the assembly.
Public propertyCode exampleAssemblyCulture
The culture information for the assembly.
Public propertyCode exampleAssemblyDelaySign
Controls delay signing of the assembly.
Public propertyCode exampleAssemblyDescription
The description of the assembly.
Public propertyCode exampleAssemblyFileBuildNumber
The build number of the assembly file.
Public propertyCode exampleAssemblyFileBuildNumberFormat
The format string to apply when converting the file build number to a text string.
Public propertyCode exampleAssemblyFileBuildNumberType
The type of update to use when setting the AssemblyFileBuildNumber property.
Public propertyCode exampleAssemblyFileMajorVersion
The major version of the assembly file.
Public propertyCode exampleAssemblyFileMinorVersion
The minor version of the assembly file.
Public propertyCode exampleAssemblyFileRevision
The revision of the assembly file.
Public propertyCode exampleAssemblyFileRevisionFormat
The format string to apply when converting the file revision to a text string.
Public propertyCode exampleAssemblyFileRevisionReset
Whether the AssemblyFileRevisionNumber will be reset to 0 when a DateString or Julian BuildNumberType is used in conjunction with an AutoIncrement AssemblyRevisionType.
Public propertyCode exampleAssemblyFileRevisionType
The type of update to use when setting the AssemblyFileRevision property.
Public propertyCode exampleAssemblyFileVersion
The complete version of the assembly file.
Public propertyCode exampleAssemblyIncludeSigningInformation
Controls whether assembly signing information is replaced in the AssemblyInfo files.
Public propertyCode exampleAssemblyInfoFiles
Specifies the list of AssemblyInfo files the task should update.
Public propertyCode exampleAssemblyInformationalVersion
The AssemblyInformationalVersion for the assembly.
Public propertyCode exampleAssemblyKeyFile
Specifies the key file used to sign the assembly.
Public propertyCode exampleAssemblyKeyName
Specifies the name of a key container within the CSP containing the key pair used to generate a strong name.
Public propertyCode exampleAssemblyMajorVersion
The major version of the assembly.
Public propertyCode exampleAssemblyMinorVersion
The minor version of the assembly.
Public propertyCode exampleAssemblyProduct
The product name of the assembly.
Public propertyCode exampleAssemblyRevision
The revision of the assembly.
Public propertyCode exampleAssemblyRevisionFormat
The format string to apply when converting the revision to a text string.
Public propertyCode exampleAssemblyRevisionReset
Whether the AssemblyRevisionNumber will be reset to 0 when a DateString or Julian BuildNumberType is used in conjunction with an AutoIncrement AssemblyRevisionType.
Public propertyCode exampleAssemblyRevisionType
The type of update to use when setting the AssemblyRevision property.
Public propertyCode exampleAssemblyTitle
The title of the assembly.
Public propertyCode exampleAssemblyTrademark
The trademark information for the assembly.
Public propertyCode exampleAssemblyVersion
The complete version of the assembly.
Public propertyCode exampleComVisible
Specifies whether the assembly is visible to COM.
Public propertyFirstDayOfWeek
Set the first day of the week for IncrementMethod.YearWeekDay. Defaults to Monday
Public propertyCode exampleGuid
The GUID for the assembly.
Public propertyMaxAssemblyFileVersion
Returns the largest assembly file version set by the task.
Public propertyMaxAssemblyVersion
Returns the largest assembly version set by the task.
Public propertyPaddingCount
Sets the number of padding digits to use, e.g. 4
Public propertyPaddingDigit
Sets the padding digit to use, e.g. 0
Public propertySkipVersioning
Set to true to skip setting version information. Default is false.
Public propertyStartDate
Sets the start date to use when using IncrementMethod.ElapsedDays
Public propertyTextEncoding
The encoding to write the new file in. The default is UTF8
Public propertyUpdateAssemblyInformationalVersion
Set to true to update the AssemblyInformationalVersion.
Public propertyUseUtc
Set to true to use UTC Date / Time in calculations. Default is false.
Top
Remarks

The primary use of the AssemblyInfo task is to set assembly version numbers at build time. The typical way to use it is to add the MSBuild.ExtensionPack.VersionNumber.Targets file to your project file, and to then specify properties in your project file to control the assembly version numbers.

Version numbers are of the form A.B.C.D, where:

  • A is the major version
  • B is the minor version
  • C is the build number
  • D is the revision

Typically the major and minor versions are fixed and do not change over the course of multiple daily builds. The build number is frequently set to increment on a daily basis, either starting at 1 and continuing from there, or as some representation of the date of the build. The revision is typically used to differentiate between multiple builds on the same day, usually starting at 1 and incrementing for each build.

To get the standard Visual Studio-style version simply add the MSBuild.ExtensionPack.VersionNumber.Targets file to your project. To override the default version numbers, such as the major and minor version, you can set the appropriate properties. For more information see the AssemblyMajorVersion and AssemblyMinorVersion items.

For use with Team Foundation Server, see this blog post: Team Build and the AssemblyInfo Task

How To: Auto-Increment Version Numbers for a Project The most common way to use the AssemblyInfo task is to add a reference to the MSBuild.ExtensionPack.VersionNumber.targets file to any project file whose AssemblyInfo you want to manage.

For standard .csproj, .vbproj, and .vjsproj files do the following:

Open the project in Visual Studio 2005 Right-click on the project in Solution Explorer and select Unload Project Right-click on the project in Solution Explorer and select Edit [project file] If the AssemblyInfoTask was installed into the Global Assembly Cache add the following line at the end of the project file after the last <Import> tag:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\ExtensionPack\MSBuild.ExtensionPack.VersionNumber.targets"/>

If the AssemblyInfoTask was installed into the user's Application Data folder add the following line at the end of the project file after the last <Import> tag:

<Import Project="$(APPDATA)\Microsoft\MSBuild\ExtensionPack\MSBuild.ExtensionPack.VersionNumber.targets"/> Save and close the project file Right-click on the project in Solution Explorer and select Reload Project With these project file modifications all builds will have auto-incrementing assembly and file versions of the following format:

1.0.date.revision

For example, the first build on November 10th, 2005 will have a version number of:

1.0.51110.00

Subsequent builds on the same day will have version numbers 1.0.51110.01, 1.0.51110.02, and so on.

Note: All AssemblyInfo.* files must have have entries with a starting value of "1.0.0.0" for AssemblyVersion and AssemblyFileVersion so the AssemblyInfoTask will work correctly. If these entries are missing from the files a build error will be generated.

Overriding the Default Version Number Behaviour In some situations the desired version number behaviour may be different than the defaults offered by the MSBuild.ExtensionPack.VersionNumber.targets file.

To set the assembly and file versions to specific numbers add the appropriate property to your project file. For example, to set the major version to 8, add the following two properties:

<AssemblyMajorVersion>8</AssemblyMajorVersion>

<AssemblyFileMajorVersion>8</AssemblyFileMajorVersion>

For more information see the assembly version properties reference.

Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <ItemGroup>
            <AssemblyInfoFiles Include="C:\a\CommonAssemblyInfo.cs"/>
            <AssemblyInfoFiles1 Include="C:\a\CommonAssemblyInfo1.cs"/>
            <AssemblyInfoFiles2 Include="C:\a\CommonAssemblyInfo2.cs"/>
        </ItemGroup>
        <!-- Update an attribute and don't do any versioning -->
        <MSBuild.ExtensionPack.Framework.AssemblyInfo ComVisible="true" AssemblyInfoFiles="@(AssemblyInfoFiles)" SkipVersioning="true"/>
        <!-- Version using YearWeekDay and set the start of the week as a Sunday -->
        <MSBuild.ExtensionPack.Framework.AssemblyInfo AssemblyInfoFiles="@(AssemblyInfoFiles1)" AssemblyBuildNumberType="YearWeekDay" FirstDayOfWeek="Sunday"/>
        <!-- Version using the number of days elapsed since a given start date-->
        <MSBuild.ExtensionPack.Framework.AssemblyInfo AssemblyInfoFiles="@(AssemblyInfoFiles2)" StartDate="1 Jan 1976" AssemblyBuildNumberType="ElapsedDays"/>
    </Target>
</Project>
See Also

Reference