gpt4 book ai didi

msbuild任务读取dll的AssemblyFileVersion

转载 作者:行者123 更新时间:2023-12-02 11:23:11 27 4
gpt4 key购买 nike

我需要读取 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

最佳答案

借用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)" />

关于msbuild任务读取dll的AssemblyFileVersion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7265690/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com