I’ve recently had to look at dynamically assigning an assembly versions based in part on the date of compilation and the version of a compiled 3rd Party library.
This looked like a simple job for the MSBuild.ExtensionPack.Framework.Assembly task in the MSBuild Extension Pack. However, this had a serious downside it locked the Assembly for the duration of the build!.
This is the Devil Line that causes the problem:
It looks innocent enough, but it loads the assembly into the current AppDomain (MSBuild’s build process) which then prevents any other process from accessing the file – even the build process itself.
To get around this, I knocked up a quick custom MSBuild Task:
The main different between my implementation and the MSBuild Extension Pack task is this line:
This line retrieves the assemblies name object (version, public key, etc, etc) without actually loading the assembly into the AppDomain, hence – no locking! Sweet.
This can now be referenced in your build scripts, like so:
The above example makes use the AssemblyInfo task in the MSBuild Extension Pack to explicitly set the version number for my assembly.