Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're using MsBuild 4.0 you can write your own <a href="http://msdn.microsoft.com/en-us/library/dd722601.aspx" rel="nofollow">inline custom Task</a> to get this done.</p> <pre><code>&lt;UsingTask TaskName="GetVersionParts" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"&gt; &lt;ParameterGroup&gt; &lt;AssemblyPath ParameterType="System.String" Required="true" /&gt; &lt;MajorVersion ParameterType="System.Int32" Output="true" /&gt; &lt;MinorVersion ParameterType="System.Int32" Output="true" /&gt; &lt;BuildVersion ParameterType="System.Int32" Output="true" /&gt; &lt;/ParameterGroup&gt; &lt;Task&gt; &lt;Using Namespace="System.Diagnostics" /&gt; &lt;Code Type="Fragment" Language="cs"&gt; &lt;![CDATA[ Log.LogMessage("Getting version details of assembly at: " + this.AssemblyPath, MessageImportance.High); Version v = Version.Parse(FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion); this.MajorVersion = v.Major; this.MinorVersion = v.Minor; this.BuildVersion = v.Build; ]]&gt; &lt;/Code&gt; &lt;/Task&gt; &lt;/UsingTask&gt; </code></pre> <p>and then reference the inline task elsewhere in your build script...</p> <pre><code>&lt;GetVersionParts AssemblyPath="$(OutputDirAbsolute)/MyAssembly.dll"&gt; &lt;Output TaskParameter="MajorVersion" PropertyName="MajorVersionNumber" /&gt; &lt;Output TaskParameter="MinorVersion" PropertyName="MinorVersionNumber" /&gt; &lt;Output TaskParameter="BuildVersion" PropertyName="BuildVersionNumber" /&gt; &lt;/GetVersionParts&gt; </code></pre> <p>Using the inline Task, you have can have easy access to each part of the assembly's build number. e.g $(MajorVersionNumber)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload