【问题标题】:msbuild task to read AssemblyFileVersion of dll读取 dll 的 AssemblyFileVersion 的 msbuild 任务
【发布时间】:2011-09-01 02:55:30
【问题描述】:

我需要阅读 dll 的 AssemblyFileVersion 而不仅仅是 Version。我试过了:

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

脚本运行但不输出任何内容。如果我将FileVersion 更改为Version,它会正确输出AssemblyVersion。如何使用我的脚本获得AssemblyFileVersion

【问题讨论】:

    标签: msbuild versioning


    【解决方案1】:

    借用 this answer,我能够创建自定义 MSBuild 任务:

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

    然后从目标中使用它:

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

    【讨论】:

      【解决方案2】:

      MSBuild Extension 包有一个可能有用的MaxAssemblyFileVersion 属性。

      更新:

      documentation 看来,GetAssemblyIdentity 任务不会返回 FileVersion

      Assemblies 参数输出的项目包含项目元数据 名为 Version、PublicKeyToken 和 Culture 的条目。

      另外,请参阅以下 StackOverflow 帖子。

      Read AssemblyFileVersion from AssemblyInfo post-compile

      【讨论】:

      • 这是一个老问题,但我也有同样的需求,想知道通过 DLL 而不是 assemblyinfo.cs 文件是否已经解决了这个问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2010-12-23
      • 2010-11-18
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      相关资源
      最近更新 更多