Automatically update the AssemblyFileVersion attribute of a .NET Assembly

Automatic AssemblyFileVersion Updates
Automatic AssemblyFileVersion Updates

There is support in .NET for automatically incrementing the AssemblyVersion of a project by using the “.*” notation. e.g.
[assembly: AssemblyVersion("0.1.*")]

Unfortunately the same functionality isn’t available for the AssemblyFileVersion. Often times, I don’t want to bump the AssemblyVersion of an assembly as it will effect the strong name signature of the assembly, and perhaps the changes (a bug fix) isn’t significant enough to warrant it. However I do want to automatically increment the file version, so that in a deployed environment, I can right click the file and establish when the file was built & released.

[important]Enter the Update-AssemblyFileVersion.ps1 file.[/important]

This powershell script, (heavily borrowed from David J Wise’s article), runs as a pre-build command on a .NET Project. Simply point the command at an assembly info file, (or GlobalAssemblyInfo.cs if you’re following my suggested versioning tactics)  and ta-da, automatically updating AssemblyFileVersions.

The Build component of the version number will be set using the following formula based on a daycount since the year 2000.

# Build = (201X-2000)*366 + (1==>366)
    $build = [int32](((get-date).Year-2000)*366)+(Get-Date).DayOfYear

The Revision component of the version number will be using the following formula based on seconds in the current day.

# Revision = (1==>86400)/2 # .net standard
    $revision = [int32](((get-date)-(Get-Date).Date).TotalSeconds / 2)

The Major & Minor components are not set to update although they could be. Simply add the following command to your Pre-Build event and you’re all set.

    -File "C:\Path\To\Update-AssemblyFileVersion.ps1"  
    -assemblyInfoFilePath "$(SolutionDir)\Project\Properties\AssemblyInfo.cs"

~Eoin C

.NET Windows Services – Tips & Tricks

Windows Services
Windows Services

If you’ve ever worked with windows services, you’ll know that they’re a very powerful tool to have in your background processing arsenal. Unfortunately they can be also quite a pain to work with in developer land. Recently we’ve been spinning up a lot of new windows service projects in work as part of a Business Intelligence Data Processing Project. I thought this would be a good time to brain dump some of the tips & tricks I’ve come across over the past few years for dealing with .Net Windows Services.

I’ll look at the basics for getting a service up and going, using the built project installer & Install Util. Then I’ll take a look at easier ways of running the service inside the IDE, and how to run the service in user interactive mode.

Finally I’ll look at ways to make the service self-installing without having to rely upon the InstallUtil.exe as well as gaining access to configuration settings during the installation process.

[important]The completed solution can be found on GitHub at [/important]

Read More “.NET Windows Services – Tips & Tricks”

Combinatorics in .NET – Part II – Creating a Nuget Package
[important] This is part 2 of a 2 part post on Combinatorics in .Net

The solution is publicly available on github;

The library can be added to any .NET Soution via Nuget;

In the last post we looked at the Combinatorics Library, a .NET Assembly which provides Combinatoric generation capabilities to your .NET Applications. Now lets look at bundling up that solution & deploying the package to Nuget. Nuget is an online .NET Package Repository & associated Visual Studio extension that makes it easy to manage external assemblies in your projects. Developers who build 3rd party libraries or tools can create a NuGet package and store the package in a NuGet repository. Other developers can then browse the repository (online or with Visual Studio) and add references to those 3rd party tools & libraries.

You can read more about Nuget here.

Read More “Combinatorics in .NET – Part II – Creating a Nuget Package”

Cyclic Reference

Xml & Json Serialization of Object Graphs with Cyclic References in .NET

Cyclic Reference
Cyclic Reference

As a WCF Developer you’ve no doubt run into some issues with object serialization at some point or another during the course of developing your applications. Either during the course of pushing your entities through a WCF Service or by attempting to serialize those object for transit through other media. Recently I ran into some issues around serializing WCF Entities with Circular References (or cyclic relationships) between parent & child Objects.


A large percentage of our company’s software work relies on moving a variety of object graphs around through WCF. These object graphs, often times contain self-references or circular references. The data we deal with is primarily related to the airline industry; specifically crew & flight schedules. It contains complicated tree structures of data with information on the flights crew-member’s fly, the duties (work-shifts) those flights belong to & the pairings, those duties are contained within. (A pairing is airline industry parlance for a collection of Duties organised into a longer 4 or 5 scheduled body of work for a crew member. Confusingly, it is not necessarily a Pair of anything).

In order to allow us to more easily navigate these object graphs, we populate a number of helper properties on the entities to allow us to traverse up and down the graph with ease. The following is an extremely simplified example of what gets populated in our Crew Schedule “Roster” Object Graph and shows the relations ships between the three previously mentioned domain entities.

Of course, this makes for some interesting cyclic situations when both the parent objects & contents of the child collections are cross-wired to one another and we want to serialize those objects for use through a WCF Service.

Read More “Xml & Json Serialization of Object Graphs with Cyclic References in .NET”

Visual Studio 2012

Visual Studio 2012 – First Impressions

Visual Studio 2012
Visual Studio 2012

Last week, I took the leap and upgraded my work machine to Visual Studio 2012 and it’s been very smooth sailing so far. The installation for starters was a breeze and there are a number of improvements & new features that Ive been very impressed by straight out of the gates.

Dark Colour Scheme

I’m a big fan of the Dark Color schemes in the my IDE and a long time user of the Son Of Obsidian style in Visual Studio 2010 so it’s nice to see some first-class support for dark, expression-blend style themes in VS2012. Open the Tools Menu, then Options and the Color Theme is the very first choice on the General Tab.

VS2012 Dark Color Theme
VS2012 Dark Color Theme

Read More “Visual Studio 2012 – First Impressions”