2011-09-01 12 views
8

Potrzebuję przeczytać AssemblyFileVersion biblioteki dll zamiast tylko Version. Próbowałem:msbuild zadanie do odczytu AssemblyFileVersion dll

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

Ten skrypt działa, ale niczego nie wyświetla. Jeśli zmienię FileVersion na Version, poprawnie wypisze on AssemblyVersion. Jak uzyskać AssemblyFileVersion z moim skryptem?

Odpowiedz

4

Zestaw MSBuild Extension ma właściwość MaxAssemblyFileVersion, która może być przydatna.

UPDATE:

Z documentation nie wyglądać zadanie GetAssemblyIdentity zwraca FileVersion.

Pozycje wyjściowe przez parametr zgromadzeniach zawierać metadane artykuł wpisy nazwanych Version, TokenKluczaPublicznego i Kultura.

Zobacz także następujący post StackOverflow.

Read AssemblyFileVersion from AssemblyInfo post-compile

+0

Jest to stary pytanie ale mam tę samą potrzebę i zastanawiam się, czy zostało to rozwiązane, czytając plik DLL, a nie plik assemblyinfo.cs? –

2

Pożyczanie od this answer, udało mi się stworzyć niestandardowy MSBuild zadanie:

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

A potem konsumować go od wewnątrz cel:

<GetFileVersion AssemblyPath="some.dll"> 
    <Output TaskParameter="Version" PropertyName="MyAssemblyFileVersion" /> 
</GetFileVersion> 
<Message Text="File version is $(MyAssemblyFileVersion)" /> 
Powiązane problemy