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

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: MSBuild AssemblyInfoTask:- Update Assemblyinfo.cs for .csproj

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=161586&SiteID=1
5/29/2007 10:59 AM | Narendra Tiwari

Post a comment





 

 

News

Employers
Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with MyGooglePageRank.com

Archives

Post Categories

Image Galleries

Articles & Magazines

ASP.Net 2.0 Compilation

ASP.Net, Blogs I refer...

Atlas

Dost

Drivers and Software Download

Garhwal

Travel Domain

WSS and WebParts

Syndication: