I need to read AssemblyFileVersion
of dll instead of just Version
. I tried:
<Target Name="RetrieveIdentities">
<GetAssemblyIdentity AssemblyFiles="some.dll">
<Output
TaskParameter="Assemblies"
ItemName="MyAssemblyIdentities"/>
</GetAssemblyIdentity>
<Message Text="%(MyAssemblyIdentities.FileVersion)" />
</Target>
The script runs but doesn't output anything. If I change FileVersion
to Version
it correctly outputs the AssemblyVersion
. How do I get AssemblyFileVersion
with my script?
It's the version number given to file as in file system. It's displayed by Windows Explorer, and never used by . NET framework or runtime for referencing.
If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there. In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.
AssemblyVersion: Specifies the version of the assembly being attributed. AssemblyFileVersion: Instructs a compiler to use a specific version number for the Win32 file version resource.
You can set the assembly version using the AssemblyVersionAttribute. Assembly attributes are usually applied in the AssemblyInfo.
Borrowing from this answer, I was able to create a custom MSBuild task:
<UsingTask
TaskName="GetFileVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<AssemblyPath ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Getting version details of assembly at: " + this.AssemblyPath, MessageImportance.High);
this.Version = FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion;
]]>
</Code>
</Task>
</UsingTask>
And then consume it from within a target:
<GetFileVersion AssemblyPath="some.dll">
<Output TaskParameter="Version" PropertyName="MyAssemblyFileVersion" />
</GetFileVersion>
<Message Text="File version is $(MyAssemblyFileVersion)" />
The MSBuild Extension Pack has a MaxAssemblyFileVersion property that may be useful.
UPDATE:
From the documentation it doesn't look like the GetAssemblyIdentity
task returns the FileVersion
.
The items output by the Assemblies parameter contain item metadata entries named Version, PublicKeyToken, and Culture.
Also, see the following StackOverflow post.
Read AssemblyFileVersion from AssemblyInfo post-compile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With