Poor man's AssemblyInfo check in MSBuild
I've seen many samples and had to personally manipulate the version information in AssemblyInfo during the build process on several occasions. However, I received a red-alert from a co-worker who want to check to make sure the default assembly info (1.0.0.0) was not being used. For his client, this situation was supposed to break the build.
I started with what I believe were the correct answers. That is - if it is a policy, catch it during the check in process using a custom check-in policy. Or at least create a custom build task to gracefully perform the checks during the build.
Unfortunately, time and customer needs didn't allow either. So I offered the cheap way out. This isn't as powerful or robust as either of the aforementioned solutions, but it should work based on our time constraints. I don't recommend that you make use of this as is, but perhaps you'll glance at it and find a different use for these built-in MSBuild tasks in some other build exercise that you run across...
The sample:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Standard item creation - in my case to find all assembly info files -->
<ItemGroup>
<AssemblyInfoFiles Include=".\**\AssemblyInfo.*"/>
</ItemGroup>
<Target Name="ReadFromFile">
<!-- Next, read all lines from all files into items -->
<ReadLinesFromFile
File="%(AssemblyInfoFiles.FullPath)" >
<Output
TaskParameter="Lines"
ItemName="ItemsFromFile"/>
</ReadLinesFromFile>
<!-- Finally, force an error if any of the lines exactly matches a predefined value -->
<Error
Text="Default assembly version (CS) detected in the build"
Condition="'%(ItemsFromFile.Identity)'=='[assembly: AssemblyVersion("1.0.0.0")]' " />
<Error
Text="Default assembly version (VB) detected in the build"
Condition="'%(ItemsFromFile.Identity)'=='<Assembly: AssemblyVersion("1.0.0.0")>' " /> </Target>
</Project>