Poor man's AssemblyInfo check in MSBuild

Published 06 February 07 06:17 PM | dmckinstry

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 ( 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 -->
    <AssemblyInfoFiles Include=".\**\AssemblyInfo.*"/>

  <Target Name="ReadFromFile">
    <!-- Next, read all lines from all files into items -->
      File="%(AssemblyInfoFiles.FullPath)" >

    <!-- Finally, force an error if any of the lines exactly matches a predefined value -->
      Text="Default assembly version (CS) detected in the build"
      Condition="'%(ItemsFromFile.Identity)'=='[assembly: AssemblyVersion(&quot;;)]' " />

      Text="Default assembly version (VB) detected in the build"
      Condition="'%(ItemsFromFile.Identity)'=='&lt;Assembly: AssemblyVersion(&quot;;)&gt;' " />



No Comments

This Blog

Microsoft VSTS Blogs

MSDN Forums

VSTS Community Blogs