[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: C# AssemblyInfo integration

From: si <sshnug.si_at_gmail.com>
Date: Tue, 1 Sep 2009 11:50:57 +0930

On Fri, Aug 28, 2009 at 5:06 PM, Jason Malinowski<jason_at_jason-m.com> wrote:
> Remember, Visual Studio project files are really MSBuild scripts in
> disguise; I believe MSBuild supports the ability to create a piece of code
> that can supply temporary files that should be used during a build. You
> could provide a new file with the appropriate [assembly:] entry...

The approach I took was to create a custom MSBuild task which used
some regex to set the parts of a version, i.e.
Attribute("Major.Minor.BuildNumber.Revision") which updates the
appropriate AssemblyInfo.cs file.

Writing your own MSBuild task is easy (easier than in NAnt), here's
the end result in one of our C# projects:

<Target Name="UpdateFrameworkVersion" Condition="'$(CIBuildNumber)' != ''">
  <UpdateVersion Attribute="AssemblyFileVersion"
BuildNumber="$(CIBuildNumber)" />

The target is called in the BeforeBuild target, our build server
(CruiseControl.NET) passes property CIBuildNumber, which is set in the
appropriate AssemblyInfo, which cascades to all our Framework
assemblies using file links, allowing us to just have to set version
in one place. The Condition check is used to prevent developer setting
AssemblyInfo when compiling locally.

So a few hours work upfront and every project we create can now reuse
this approach. It doesn't matter where the number(s) come from, so
long as you can set an MSBuild property you can set it in any part of
the version. UpdateVersion task has [Required] properties Attribute
and AssemblyInfo, and [Output] properties Major, Minor, BuildNumber
and Revision.

FWIW, initially I used Subversion revision number as the "Revision"
part of the version, but dropped it because:

1. Each version part is limited in size to int16, so once you reach
revision 32,768 you're S.O.L :)
2. Windows installer (MSI) only uses Major.Minor.BuildNumber for
determining a files version (if it has version meta-data).

Since we manually set Major.Minor, and wanted to link BuildNumber to
cruise control, there were no version parts left, and no real value
because the incremented BuildNumber ensures uniqueness, and also
allows us to find the Subversion revision as our release build always
takes an svn copy, thus linking CI build number and Subversion

Hope that helps,


To unsubscribe from this discussion, e-mail: [users-unsubscribe_at_subversion.tigris.org].
Received on 2009-09-01 04:33:21 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.