It is very easy to use the above task in conjuction with the target file Microsoft.VersionNumber.targets. by putting following import tag at the end of .csproj file.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets')" />
Here All the Assembly attributes and their values are defined in this target file, and the moment we compile the project (.csproj), all the assembly attributes available in assemblyinfo.cs are updated from the attributes value defined in target file.
Now consider a case When we have several ClassLibrary projects to be compiled in our msbuild script. Here we need to dynamically change the assembly attribute values for the projects like AssemblyTitle, Version, etc..
Following example shows how we can pass these assembly attributes values from msbuild script:-
<Target Name="CompileLibraries" >
<!--Compiling project1-->
<Exec Command="MSBuild.exe $(BuildDirectory)\Solution\project1.csproj /t:Rebuild
/p:AssemblyRevisionType="NoIncrement"
/p:AssemblyFileRevisionType="NoIncrement"
/p:AssemblyMajorVersion=$(Major)
/p:AssemblyMinorVersion=$(Minor)
/p:AssemblyBuildNumber=$(BuildNumber)
/p:AssemblyRevision=$(RevisionNumber)
/p:AssemblyFileMajorVersion=$(Major)
/p:AssemblyMinorVersion=$(Minor)
/p:AssemblyFileBuildNumber=$(BuildNumber)
/p:AssemblyFileRevision=$(RevisionNumber)
/p:AssemblyKeyFile=$(AssemblyKeyFile)
/p:AssemblyTitle=PROJECT1"
WorkingDirectory="$(MSBuildBinPath)"/>
<!--Compiling project2-->
<Exec Command="MSBuild.exe $(BuildDirectory)\Solution\project2.csproj /t:Rebuild
/p:AssemblyRevisionType="NoIncrement"
/p:AssemblyFileRevisionType="NoIncrement"
/p:AssemblyMajorVersion=$(Major)
/p:AssemblyMinorVersion=$(Minor)
/p:AssemblyBuildNumber=$(BuildNumber)
/p:AssemblyRevision=$(RevisionNumber)
/p:AssemblyFileMajorVersion=$(Major)
/p:AssemblyMinorVersion=$(Minor)
/p:AssemblyFileBuildNumber=$(BuildNumber)
/p:AssemblyFileRevision=$(RevisionNumber)
/p:AssemblyKeyFile=$(AssemblyKeyFile)
/p:AssemblyTitle=PROJECT2"
WorkingDirectory="$(MSBuildBinPath)"/>
</Target>
in above target we are setting the attributes for two different projects dynamically. here values given inside $() are MSBuild properties and should be inside a propertygroup:-
<PropertyGroup>
<Major>3</Major>
<Minor>0</Minor>
<BuildNumber>0</BuildNumber>
<RevisionNumber>0</RevisionNumber>
<AssemblyRevisionType></AssemblyRevisionType>
<AssemblyKeyFile></AssemblyKeyFile>
<BuildType></BuildType>
</PropertyGroup>
Download MSBuild AssemblyInfoTask