2011-09-01 25 views
8

Tôi cần phải đọc AssemblyFileVersion của dll thay vì chỉ Version. Tôi đã thử:msbuild nhiệm vụ để đọc AssemblyFileVersion của dll

<Target Name="RetrieveIdentities"> 
    <GetAssemblyIdentity AssemblyFiles="some.dll"> 
     <Output 
      TaskParameter="Assemblies" 
      ItemName="MyAssemblyIdentities"/> 
    </GetAssemblyIdentity> 
    <Message Text="%(MyAssemblyIdentities.FileVersion)" /> 
</Target> 

Tập lệnh chạy nhưng không xuất ra bất kỳ thứ gì. Nếu tôi thay đổi FileVersion thành Version, nó sẽ xuất ra chính xác AssemblyVersion. Làm cách nào để nhận được AssemblyFileVersion bằng tập lệnh của tôi?

Trả lời

4

Gói MSBuild Extension có thuộc tính MaxAssemblyFileVersion có thể hữu ích.

UPDATE:

Từ documentation nó không giống như nhiệm vụ GetAssemblyIdentity trả về FileVersion.

Mục đầu ra theo tham số Assemblies chứa siêu dữ liệu mục mục có tên Phiên bản, PublicKeyToken và Văn hóa.

Ngoài ra, hãy xem bài đăng StackOverflow sau đây.

Read AssemblyFileVersion from AssemblyInfo post-compile

+0

Đây là một câu hỏi cũ nhưng tôi có cùng một nhu cầu và tự hỏi nếu điều này đã được giải quyết đọc DLL không phải là file assemblyinfo.cs? –

2

vay từ this answer, tôi đã có thể tạo ra một tùy chỉnh MSBuild nhiệm vụ:

<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> 

Và sau đó tiêu thụ nó từ bên trong một mục tiêu:

<GetFileVersion AssemblyPath="some.dll"> 
    <Output TaskParameter="Version" PropertyName="MyAssemblyFileVersion" /> 
</GetFileVersion> 
<Message Text="File version is $(MyAssemblyFileVersion)" /> 
Các vấn đề liên quan