Alex Rivera | Logout

MSbuild for updating the assemblyinfo file

Asked 2012-01-05T08:17:32.880
13

I am writing a batch file to automate a series of tasks. One of these tasks is to update the version of the dlls in my solution, by editing the assemblyinfo.cs file in the various projects in my solution; and then finally calling msbuild.exe to compile the solution.

In this regard, is it possible to write a command line script to update the various assemblyinfo.cs files in my .net solution. I would prefer to call msbuild from the commandline itself and not create another msbuild scripted file.

How does one do this using MSBuild? Is there any other way to do it?

Thanks for your time...

Edit
Report

1 Answer

10

This is the MSBuild target code where I update all my assemblyinfo.cs files (You have to init AssemblyInfoFilesToUpdate items collections before using this target):

  <!-- Update all the assembly info files with generated version info -->
  <Target Name="AfterGet" Condition="'$(ServerBuild)'=='true' And '$(BuildVersion)'!=''">
    <Message Text="Modifying AssemblyInfo files..." />
    <!-- Clear read-only attributes -->
    <Attrib Files="@(AssemblyInfoFilesToUpdate)" Normal="true" />
    <!-- Update AssemblyVersion -->
    <FileUpdate Files="@(AssemblyInfoFilesToUpdate)"
            Regex="AssemblyVersion\(&quot;.*&quot;\)\]"
            ReplacementText="AssemblyVersion(&quot;$(BuildVersion)&quot;)]" />
    <!-- Update AssemblyFileVersion -->
    <FileUpdate Files="@(AssemblyInfoFilesToUpdate)"
            Regex="AssemblyFileVersion\(&quot;.*&quot;\)\]"
            ReplacementText="AssemblyFileVersion(&quot;$(BuildVersion)&quot;)]" />
    <Message Text="AssemblyInfo files updated to version &quot;$(BuildVersion)&quot;" />
  </Target>

I'm using FileUpdate task from MSBuildCommunityTasks.

answered 2012-01-05T22:02:34.703

Your Answer