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?
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
精彩评论